In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to achieve Wechat fission red packets in C#. It is very detailed and has a certain reference value. Interested friends must finish reading it!
1. Introduction of fission red packet
Users who receive corporate fission red envelopes can continue to help their friends receive red envelopes and spread them to more friends in the form of fission, giving marketing more fun and pleasure! Fission red packets continue to strengthen the enterprise brand effect and form split communication, which is a marketing tool for brand publicity. The enterprise only needs to specify the number and total amount of a group of red packets, and WeChat Pay calculates the amount of each red packet, which is simple and convenient.
WeChat Pay fission red packets to WeChat Pay merchants to develop, the specific capabilities are as follows:
1. When the merchant calls the interface, it sends out a set of fission red packets by specifying the sending amount and specifying a sending object.
2. After the designated sender receives the red packet, the money goes directly into Wechat's change, giving users WeChat Pay's original smooth experience.
3. The designated sender can share the remaining red packets in the combination with friends, and friends can continue to receive them, forming a communication effect and magnifying the brand value of the enterprise.
The overall processing process and interface of fission red packets are not much different from those of ordinary cash red packets. It should be easy to understand the encapsulation and use of fission red packets.
Fission red packet interface, used by enterprises to send cracking red packets to Wechat users
Currently, it is supported to send a specified amount of fission red packets to the openid of specified Wechat users. (for openid, please see Wechat Public platform developer documentation: Web Authorization to obtain basic user Information)
The relationship between the API parameters and the actual results obtained by users is as follows:
API call request indicates whether a certificate is required for the request Url https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack. (for more information on certificate and usage, please see Merchant Certificate). POST is the same as the cash red packet described earlier. We can also divide the parameters of fission red packet into two parts, one is general parameters, and the other is business parameters, as shown below.
2. C # code encapsulation of fission red packet
From the parameters passed above, we can divide it into two parts, when we pass in the following parameters
When the above parameters are submitted to the address: https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack, the following XML will be returned upon success.
10010404 3
If it fails, the XML returned will have a lot less information, as shown below.
10010404 3
According to these rules, we encapsulate the interface and implementation code of fission red packets for better use.
For example, based on the similarity of the entity classes of ordinary cash red packets and fission red packets, we design several classes to store information, and the object relationship of the passed parameters is shown in the following figure.
Similarly, for the returned red packet result, because we need to consider the information return at the time of error and the successful information return, we design the relationship of the return result class as follows.
According to the above design idea, the class code we designed is as follows.
/ data information of sending fission red packets / public class SendGroupRedPackJson: BaseRedPackJson {/ the setting method of red packet amount / ALL_RAND- is all random. The merchant specifies the total amount and the total number of people who send red packets. WeChat Pay randomly calculates the amount of each red packet / public string amt_type {get; set } public SendGroupRedPackJson () {this.amt_type = "ALL_RAND";}}
The code for the resulting object class is as follows.
/ return result of sending red packet / public class SendRedPackResult: PayResult {/ merchant order number / public string mch_billno {get; set } / merchant appid. All appid passed into the API should be official account appid (applied in mp.weixin.qq.com), not APP appid (applied in open.weixin.qq.com). / public string wxappid {get; set;} / users receiving red packets / users' openid / public string re_openid {get; set;} / payment amount under wxappid, unit points / public int total_amount {get; set } / Red packet delivery time / public string send_time {get; set;} / Wechat order number of the red packet order / public string send_listid {get; set;}}
In this way, with the code of these objects, according to the description of the interface, we still follow the interface design introduced in the previous essay to achieve the fission red packet code processing.
/ / WeChat red packet, the operation of shaking red envelopes API interface / public interface ILotteryApi {/ for enterprises to send cash red envelopes to individual Wechat users. Merchant certificate is required / / currently, it is supported to issue red packets of a specified amount to the openid of specified Wechat users. / SendRedPackResult SendRedPack (SendRedPackJson json); / for enterprises to send cracking red packets to Wechat users personally. Merchant certificate is required / / currently, it is supported to issue a specified amount of fission red packets to the openid of specified Wechat users. / SendRedPackResult SendGroupRedPack (SendGroupRedPackJson json)
Then the interface code that implements them is shown below.
/ WeChat red packet management class / public class LotteryApi: ILotteryApi {# region fission red packet description / / WeChat Pay fission red packet development to WeChat Pay merchants, the specific capabilities are as follows: / / 1. When the merchant calls the API Send a group of fission red packets / / 2 by specifying the sending amount and a designated sender, and after the designated sender receives the red packet, the money goes directly into Wechat's change. bring the user WeChat Pay's original fluency experience / / 3. The designated sender can share the remaining red packets in the combination with friends, and friends can continue to receive them, forming a communication effect. Magnifying the corporate brand value # endregion / is used for enterprises to send cracking red envelopes to Wechat users. Merchant certificate is required / / currently, it is supported to issue a specified amount of fission red packets to the openid of specified Wechat users. / public SendRedPackResult SendGroupRedPack (SendGroupRedPackJson json) {CheckAccount (); / / check the object attribute value of AccountInfo WxPayData data = new WxPayData (); data.SetValue ("wxappid", AccountInfo.UniteAppId); / / Public account appid data.SetValue ("mch_id", AccountInfo.MchID) / / merchant number data.SetValue ("nonce_str", data.GenerateNonceStr ()); / / random string data.SetValue ("send_name", AccountInfo.Name); / / red packet sender name / / merchant order number (each order number must be unique): a number that cannot be repeated within a day in mch_id+yyyymmdd+10 bits. / / the API supports reentry according to the merchant's order number, and can be called again if a timeout occurs. Data.SetValue ("mch_billno", data.GenerateOutTradeNo (AccountInfo.MchID)); data.SetValue ("re_openid", json.re_openid); / / seed user (first user) who receives red packets data.SetValue ("total_amount", json.total_amount) / / Total amount of red packets, that is, the total amount of a group of red packets, including the sharers' red packets and fission red packets, in data.SetValue ("total_num", json.total_num); / / the total number of red packets issued, that is, how many people can receive the group of red packets (including sharers) data.SetValue ("wishing", json.wishing) / / data.SetValue ("act_name", json.act_name); data.SetValue ("remark", json.remark); data.SetValue ("amt_type", json.amt_type); data.SetValue ("sign", data.MakeSign (AccountInfo.PayAPIKey)) / / finally generate the signature var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack"; return Helper.GetPayResultWithCert (data, url, AccountInfo.CertPath, AccountInfo.CertPassword);}.
3. The call and effect display of fission red packet interface.
Above, we encapsulate the interface of fission red packet. If we need to send fission red packet, we can directly call the above interface to send red packet.
For example, the code that calls the interface is as follows.
/ / fission red packet SendGroupRedPackJson groupJson = new SendGroupRedPackJson () {act_name = "Kung Xi Fa Tsai", remark = "enterprise red packet", wishing = "enterprise red packet", total_amount = 600, total_num = 4 Re_openid = tosendOpenId, / / OpenID sent to the user} Var groupResult = hbApi.SendGroupRedPack (groupJson); message = string.Format ("Enterprise sends fission red packets: {0} {1}", groupResult.Success? Success: failure, groupResult.Message); Console.WriteLine (message); Console.WriteLine (groupResult.ToJson ())
The object initialization code of hbApi is as follows
ILotteryApi hbApi = new LotteryApi (accountInfo)
Finally, we can see the fission red packets sent on Wechat.
Since the amount of red packets sent needs to be greater than 1 yuan, then if the amount we send is larger, then the amount of red packets removed by each person is different, as shown in the following figure.
The above is all the contents of this article "how to achieve Wechat fission red packets". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 212
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.