亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
1. The concept and use of cash red envelopes
2. Description of the cash red envelopeAPI interface and The C# package
Interface call request description
Request Parameters
3. Results of using WeChat red envelopes
Home WeChat Applet WeChat Development C# development of WeChat portal and application of encapsulation and use of WeChat cash red envelopes

C# development of WeChat portal and application of encapsulation and use of WeChat cash red envelopes

Mar 07, 2017 am 09:54 AM

After the last essay, after improving and reconstructing the entire WeChat framework, WeChat payment, corporate payment, cash red envelopes, vouchers and various card coupons have been packaged, and WeChat payment has been included and the shake red envelope part are common parts of official accounts and enterprise accounts. These payment-related interfaces can be called in official accounts and enterprise accounts. After a series of optimization and sorting, these contents will be added one by one. Introducing, hope everyone likes and supports.

1. The concept and use of cash red envelopes

1) Usage scenarios

WeChat Pay cash red envelopes are developed for WeChat Pay merchants. The specific capabilities are as follows:

◆ When merchants call the interface, they issue red envelopes by specifying the sending object and the sending amount. This method allows merchants to flexibly apply it to a variety of rich activity scenarios

◆ Receive After receiving the red envelope, the user's funds are directly transferred to WeChat change, avoiding the complicated award process and giving users the smooth experience of WeChat payment.

2) WeChat red envelope sending rules

Sending frequency rules

◆ The number of red envelopes sent per minute shall not exceed 1,800;

◆ The same merchant number, the maximum number of red envelopes sent per minute The same user sends a red envelope;

Red envelope rules

◆ The amount of a single red envelope is between [1.00 yuan, 200.00 yuan];

◆ The same red envelope can only be sent to one user; (If the above rules do not meet your needs, please send an email to wxhongbao@tencent.com for upgrade instructions)

◆ If the red envelope is not claimed 72 hours after it is issued, it will be processed Refund

3) WeChat red envelope interface calling process

◆Backend API call: communicate with the development team in detail when entering the joint debugging process;

◆ Notify the server: Inform the server of the openID of the user who received the WeChat red envelope, and inform the server of the amount received by the user;

◆ Deduct money from the business account: After the server obtains the information, it will deduct the money from the corresponding business account Get the corresponding amount;

◆ Call failure: The call fails due to non-compliance with the sending rules, insufficient balance of the business account, etc., and feedback to the caller;

◆ Successful sending: public with WeChat red envelope The account sends the corresponding red envelope to the corresponding user;

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用


2. Description of the cash red envelopeAPI interface and The C# package

is used by enterprises to send red envelopes to individual WeChat users. It currently supports issuing red envelopes of specified amounts to the openid of designated WeChat users.

Although cash red envelopes can be issued through the merchant backend of WeChat, we can also use the interface API provided by WeChat to send cash red envelopes.


Interface call request description


Request Url https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
Is it required? The certificate is (see the merchant certificate for certificate and usage instructions)
Request method POST


Request Parameters


##Field nameFieldRequiredExample valueType Description##Random string Signature Merchant order numberMerchant order number (each order number must be unique) Merchant numberpublic account appidMerchant nameuser openidUsers who accept red envelopesPayment amountTotal number of people to whom red envelopes are issuedThe total number of people given red envelopesRed Packet BlessingsIp addressActivity nameRemarks

Data example:


<xml><xml>?
??<sign><![CDATA[E1EE61A91C8E90F299DE6AE075D60A2D]]></sign>??
??<mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno>??
??<mch_id><![CDATA[888]]></mch_id>??
??<wxappid><![CDATA[wxcbda96de0b165486]]></wxappid>??
??<send_name><![CDATA[send_name]]></send_name>??
??<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>??
??<total_amount><![CDATA[200]]></total_amount>??
??<total_num><![CDATA[1]]></total_num>??
??<wishing><![CDATA[恭喜發(fā)財(cái)]]></wishing>??
??<client_ip><![CDATA[127.0.0.1]]></client_ip>??
??<act_name><![CDATA[新年紅包]]></act_name>??
??<remark><![CDATA[新年紅包]]></remark>??
??<nonce_str><![CDATA[50780e0cca98c8c8e814883e5caa672e]]></nonce_str>?
??</xml>

The above is a description of the interface and input parameters, generally In this case, we need to decide how to implement C# code encapsulation based on these. First, we define the interfaces and classes we need, as shown below.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

By analyzing the above interface description, we can find that some of the interfaces are fixed conventional parameters, that is, the identity information of general public accounts or enterprise accounts, and some are business parameters, so we separate them separately, which is conducive to our encapsulation and use of the interface. We can obtain those regular parameters through the official account identity. For business information, we can define an entity class to carry out data Just store and exchange.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

corresponds to the fixed conventional parameters in the above figure, as shown below in the interface description.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

Therefore, we can set and obtain this information from the account. We can configure them in the management background, and then take them out and use them in the code logic.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

According to the above introduction, we can define the red packet interface code as follows.

///?<summary>
????///?微信紅包(搖一搖紅包)操作API
????///?</summary>
????public?interface?ILotteryApi
????{??????????????
????????///?<summary>
????????///?用于企業(yè)向微信用戶個(gè)人發(fā)現(xiàn)金紅包。需要商戶證書
????????///?目前支持向指定微信用戶的openid發(fā)放指定金額紅包。
????????///?</summary>
????????///?<returns></returns>
????????SendRedPackResult?SendRedPack(SendRedPackJson?json);

SendRedPackJson is the business parameter we changed. We defined a class to carry information to facilitate the transfer of information through the interface.

///?<summary>
????///?現(xiàn)金紅包和裂變紅包的基礎(chǔ)信息
????///?</summary>
????public?class?BaseRedPackJson
????{
????????///?<summary>
????????///?接受紅包的用戶
????????///?用戶openid????
????????///?</summary>
????????public?string?re_openid?{?get;?set;?}

????????///?<summary>
????????///?付款金額,單位分
????????///?</summary>
????????public?int?total_amount?{?get;?set;?}

????????///?<summary>
????????///?紅包發(fā)放總?cè)藬?shù)
????????///?</summary>
????????public?int?total_num?{?get;?set;?}

????????///?<summary>
????????///?紅包祝福語(yǔ)
????????///?</summary>
????????public?string?wishing?{?get;?set;?}

????????///?<summary>
????????///?活動(dòng)名稱
????????///?</summary>
????????public?string?act_name?{?get;?set;?}

????????///?<summary>
????????///?備注信息
????????///?</summary>
????????public?string?remark?{?get;?set;?}
????}

????///?<summary>
????///?發(fā)送紅包的數(shù)據(jù)信息
????///?</summary>
????public?class?SendRedPackJson?:BaseRedPackJson
????{
????????///?<summary>
????????///?調(diào)用接口的機(jī)器Ip地址
????????///?</summary>
????????public?string?client_ip?{?get;?set;?}

????????public?SendRedPackJson()
????????{
????????????this.total_num?=?1;//紅包發(fā)放總?cè)藬?shù)
????????}
????}

According to the definition of the above parameters, we implement the interface of the cash red envelope. The specific code is as follows. The logical content inside is mainly to pass in the regular Parameters and business parameters, then call the interface address to submit data (POST), obtain the returned results and parse them.

///?<summary>
????????///?用于企業(yè)向微信用戶個(gè)人發(fā)現(xiàn)金紅包。需要商戶證書
????????///?目前支持向指定微信用戶的openid發(fā)放指定金額紅包。
????????///?</summary>
????????///?<returns></returns>
????????public?SendRedPackResult?SendRedPack(SendRedPackJson?json)
????????{
????????????CheckAccount();//檢查AccountInfo的對(duì)象屬性值

????????????//加入常規(guī)的參數(shù)
????????????WxPayData?data?=?new?WxPayData();
????????????data.SetValue("wxappid",?AccountInfo.UniteAppId);//公眾賬號(hào)appid
????????????data.SetValue("mch_id",?AccountInfo.MchID);//商戶號(hào)
????????????data.SetValue("nonce_str",?data.GenerateNonceStr());//隨機(jī)字符串
????????????data.SetValue("send_name",?AccountInfo.Name);//????紅包發(fā)送者名稱
????????????
????????????//商戶訂單號(hào)(每個(gè)訂單號(hào)必須唯一)?組成:mch_id+yyyymmdd+10位一天內(nèi)不能重復(fù)的數(shù)字。
????????????//接口根據(jù)商戶訂單號(hào)支持重入,如出現(xiàn)超時(shí)可再調(diào)用。
????????????data.SetValue("mch_billno",?data.GenerateOutTradeNo(AccountInfo.MchID));

????????????data.SetValue("re_openid",?json.re_openid);
????????????data.SetValue("total_amount",?json.total_amount);
????????????data.SetValue("total_num",?json.total_num);
????????????data.SetValue("wishing",?json.wishing);
????????????data.SetValue("client_ip",?json.client_ip);
????????????data.SetValue("act_name",?json.act_name);
????????????data.SetValue("remark",?json.remark);

????????????data.SetValue("sign",?data.MakeSign(AccountInfo.PayAPIKey));//最后生成簽名

????????????var?url?=?"https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
????????????return?Helper.GetPayResultWithCert<SendRedPackResult>(data,?url,?AccountInfo.CertPath,?AccountInfo.CertPassword);
????????}

The operation of sending red envelopes requires a certificate, so the corresponding certificate needs to be added. The certificate is downloaded from the WeChat merchant platform.

Download the certificate from the [API Security] project in the merchant backend for use in our development environment.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

After downloading the certificate, in a Windows environment, we generally need to double-click to install it and enter the required merchant number as the password.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

In the code, we can use the certificate class to add

HttpHelper?helper?=?new?HttpHelper();

????????????helper.ClientCertificates?=?new?X509CertificateCollection();
????????????certPath?=?Path.Combine(System.Environment.CurrentDirectory,?certPath);
????????????helper.ClientCertificates.Add(new?X509Certificate2(certPath,?certPassword));
????????????string?response?=?helper.GetHtml(url,?xml,?true);

3. Results of using WeChat red envelopes

For example, our calling code in the test example is as follows.

//現(xiàn)金紅包
????????????????SendRedPackJson?packJson?=?new?SendRedPackJson()
????????????????{
????????????????????act_name?=?"恭喜發(fā)財(cái)",
????????????????????client_ip?=?NetworkUtil.GetIPAddress(),
????????????????????remark?=?"企業(yè)紅包",
????????????????????wishing?=?"企業(yè)紅包",
????????????????????total_amount?=?100,
????????????????????total_num?=?1,
????????????????????re_openid?=?tosendOpenId?//發(fā)送給用戶的OpenID
????????????????};
????????????????var?result?=?hbApi.SendRedPack(packJson);
????????????????var?message?=?string.Format("企業(yè)發(fā)送紅包:{0}?{1}",?result.Success???"成功"?:?"失敗",?result.Message);
????????????????Console.WriteLine(message);
????????????????Console.WriteLine(result.ToJson());

The hbApi is the structure of the above interface, as shown in the following code.

AccountInfo??accountInfo?=?new?AccountInfo()
????{
???????Name?=?this.SendName,
????????AppID?=?this.AppId,
????????AppSecret?=?this.AppSecret,
????????MchID?=?this.MchID,
????????PayAPIKey?=?this.PayAPIKey,
????????CertPath?=?this.CertPath,
????????CertPassword?=?this.CertPassword,
?????????PayNotifyUrl?=?this.PayNotifyUrl
?????};
?ILotteryApi?hbApi?=?new?LotteryApi(accountInfo);

After successful call, we can see the red envelope information results in the conversation of the official account. The following is the entire process of sending and opening the red envelope.

C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用 C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用 C#開(kāi)發(fā)微信門戶及應(yīng)用微信現(xiàn)金紅包的封裝及使用

For more C# development of WeChat portal and application of WeChat cash red envelope packaging and use, please pay attention to the PHP Chinese website for related articles!


nonce_str is 5K8264ILTKCH16CQ2502SI8ZNMTM67VS String(32) Random string, no longer than 32 characters
sign is C380BEC2BFD727A4B6845133519F3AD6 String(32) See signature generation algorithm for details
mch_billno is 10000098201411111234567890 String(28)

Composition: mch_id+yyyymmdd+10 digits cannot be repeated within one day number.

The interface supports re-entry based on the merchant's order number. If a timeout occurs, it can be called again.

mch_id is 10000098 String(32) The merchant number assigned by WeChat payment
wxappid is wx8888888888888888 String(32) The public account ID assigned by WeChat (corporate number corpid is this appId). All appids passed in through the interface should be the appid of the public account (applied at mp.weixin.qq.com), not the appid of the APP (applied at open.weixin.qq.com).
send_name is Tianhong Department Store String(32) Red envelope sender name
re_openid is oxTWIuGaIt6gTKsQRLau2M0yL16E String(32 )

The user’s openid under wxappid

total_amount is 1000 int Payment amount, unit points
total_num is 1 int

total_num=1

wishing Yes Thank you for participating in the lantern riddle guessing activity, and I wish you a happy Lantern Festival! String(128) Red envelope blessings
client_ip is 192.168.0.1 String(15) Machine IP address calling the interface
act_name is Guessing lantern riddles and grabbing red envelope activities String(32) Activity name
remark Yes The more you guess, the more you get, come and grab it! String(256) Remarks
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72