


C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation
Mar 07, 2017 am 09:41 AM1. Introduction to enterprise payment
The so-called enterprise payment refers to, after the function is opened, such as customer claims, surrender, and product return in the insurance industry. Operations such as payment, distribution of bonuses for collection activities, and lottery interactions can all be completed through corporate payment. Previously, WeChat Pay could only provide customers with one-way payments to businesses.
If the merchant needs to pay the user, he or she can directly transfer the money into the user's "WeChat Change". WeChat Pay will notify the user of the change, and the change receipt and expenditure details will display the corresponding record. For the historical client version without change account, the funds will be entered into the user's red envelope account. There is no message from WeChat Pay to notify the user, and the enterprise can choose to reach the user on its own.
Enterprise accounts that have passed the certification can activate the WeChat payment function. A certified enterprise account can apply for the WeChat payment function in the "WeChat Payment" portal of the "Service Center" of the management platform. After opening the WeChat payment function, the enterprise account will have two functions: collection and payment. If a payment is made from a user account to an enterprise account, the money will go into the merchant account associated with the enterprise account. At the same time, enterprise accounts can pay user accounts through WeChat red envelopes or WeChat transfers.
Enterprise payment provides the function for enterprises to pay users, and supports enterprises to make payments through the API interface or operate payments through the WeChat payment merchant platform web function.
Functions involving fund operations have high security requirements and require the operator to install a certificate (Merchant Platform - Account Settings - Password Security - Operation Certificate); operate through API or web pages, and make payments to target users (enterprises can Target users based on APPID+OpenID). For users who have real-name authentication, WeChat Pay can provide the optional function of verifying the consistency of their real names.
Enterprise payment tips:
◆ For payments to the same real-name user, the single daily limit is 2W/2W
◆ For payments to the same non-real-name user User payment, the single daily limit is 2000/2000
◆ The total payment limit for a merchant on the same day is 100W
◆Only supports the APPID that has been bound to the merchant number;
◆ For the target users of payment, users who have been authenticated by WeChat Pay can provide the function of verifying their real names. Users who have not been authenticated by real name cannot be verified. Enterprises can choose the verification type according to the security level of their own business;
◆ The payment amount must be less than or equal to the merchant's current available balance;
◆ For the paid records, the enterprise can view the corresponding data through enterprise payment query.
2. Enterprise payment API
The enterprise payment business is based on the fund management capabilities of the WeChat payment merchant platform. In order to assist merchants with convenience Easily realize corporate payments to individuals, and provide the function of completing corporate payments through API for some merchants with development capabilities.
For example, the current insurance industry surrenders policies, pays benefits, and settles claims to customers.
Enterprise payment will use the merchant's available balance, and it is necessary to ensure that the available balance is sufficient. To check the available balance, recharge, and withdraw money, please log in to the "Fund Management" of the merchant platform to operate.
Interface address
Interface link: https:/ /api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
<xml> <mch_appid>wxe062425f740c30d8</mch_appid> <mchid>10000098</mchid> <nonce_str>3PG2J4ILTKCH16CQ2502SI8ZNMTM67VS</nonce_str> <partner_trade_no>100000982014120919616</partner_trade_no> <openid>ohO4Gt7wVPxIT1A9GjFaMYMiZY1s</openid> <check_name>OPTION_CHECK</check_name> <re_user_name>張三</re_user_name> <amount>100</amount> <desc>節(jié)日快樂(lè)!</desc> <spbill_create_ip>10.2.3.10</spbill_create_ip> <sign>C97BDBACF37622775366F38B629F45E3</sign> </xml>Example of successfully returned data:
<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[]]></return_msg> <mch_appid><![CDATA[wxec38b8ff840bd989]]></mch_appid> <mchid><![CDATA[10013274]]></mchid> <device_info><![CDATA[]]></device_info> <nonce_str><![CDATA[lxuDzMnRjpcXzxLx0q]]></nonce_str> <result_code><![CDATA[SUCCESS]]></result_code> <partner_trade_no><![CDATA[10013574201505191526582441]]></partner_trade_no> <payment_no><![CDATA[1000018301201505190181489473]]></payment_no> <payment_time><![CDATA[2015-05-19 15:26:59]]></payment_time> </xml>According to the above interface description, as well as input and return parameters, we can build the corresponding C# code interface
/// <summary> /// 微信支付接口 /// </summary> public interface ITenPayApi { /// <summary> /// 企業(yè)付款(請(qǐng)求需要雙向證書) /// 企業(yè)付款業(yè)務(wù)是基于微信支付商戶平臺(tái)的資金管理能力,為了協(xié)助商戶方便地實(shí)現(xiàn)企業(yè)向個(gè)人付款, /// 針對(duì)部分有開發(fā)能力的商戶,提供通過(guò)API完成企業(yè)付款的功能。 比如目前的保險(xiǎn)行業(yè)向客戶退保、給付、理賠。 /// 企業(yè)付款將使用商戶的可用余額,需確??捎糜囝~充足。查看可用余額、充值、提現(xiàn)請(qǐng)登錄商戶平臺(tái)“資金管理”進(jìn)行操作。https://pay.weixin.qq.com/ /// 注意:與商戶微信支付收款資金并非同一賬戶,需要單獨(dú)充值。 /// </summary> /// <param name="json">企業(yè)支付數(shù)據(jù)</param> /// <returns></returns> CorpPayResult CorpPay(CorpPayJson json); ..............The above CorpPayJson and CorpPayResult are the incoming parameters and the obtained result content respectively. The object information of the two can be defined according to the parameters.
/// <summary> /// 企業(yè)付款的數(shù)據(jù)信息 /// </summary> public class CorpPayJson { public CorpPayJson() { this.check_name = "FORCE_CHECK"; } /// <summary> /// 微信支付分配的終端設(shè)備號(hào) /// </summary> public string device_info { get; set; } /// <summary> /// 用戶openid /// </summary> public string openid { get; set; } /// <summary> /// 校驗(yàn)用戶姓名選項(xiàng),可以使用 PayCheckName枚舉對(duì)象獲取名稱 /// NO_CHECK:不校驗(yàn)真實(shí)姓名 /// FORCE_CHECK:強(qiáng)校驗(yàn)真實(shí)姓名(未實(shí)名認(rèn)證的用戶會(huì)校驗(yàn)失敗,無(wú)法轉(zhuǎn)賬) /// OPTION_CHECK:針對(duì)已實(shí)名認(rèn)證的用戶才校驗(yàn)真實(shí)姓名(未實(shí)名認(rèn)證用戶不校驗(yàn),可以轉(zhuǎn)賬成功) /// </summary> public string check_name { get; set; } /// <summary> /// 收款用戶真實(shí)姓名。 /// 如果check_name設(shè)置為FORCE_CHECK或OPTION_CHECK,則必填用戶真實(shí)姓名 /// </summary> public string re_user_name { get; set; } /// <summary> /// 企業(yè)付款金額,單位為分 /// </summary> public int amount { get; set; } /// <summary> /// 企業(yè)付款操作說(shuō)明信息。必填。 /// </summary> public string desc { get; set; } /// <summary> /// 調(diào)用接口的機(jī)器Ip地址 /// </summary> public string spbill_create_ip { get; set; } }
/// <summary> /// 企業(yè)付款操作的返回結(jié)果 /// </summary> public class CorpPayResult : PayResult { /// <summary> /// 微信分配的公眾賬號(hào)ID(企業(yè)號(hào)corpid即為此appId) /// </summary> public string mch_appid { get; set; } /// <summary> /// 微信支付分配的終端設(shè)備號(hào) /// </summary> public string device_info { get; set; } /// <summary> /// 商戶使用查詢API填寫的單號(hào)的原路返回. /// </summary> public string partner_trade_no { get; set; } /// <summary> /// 企業(yè)付款成功,返回的微信訂單號(hào) /// </summary> public string payment_no { get; set; } /// <summary> /// 企業(yè)付款成功時(shí)間 /// </summary> public string payment_time { get; set; } }
企業(yè)付款的API實(shí)現(xiàn)和前面兩種紅包的處理方式 差不多,一個(gè)是傳入常規(guī)的賬號(hào)信息,一個(gè)是傳入業(yè)務(wù)參數(shù),然后提交獲取結(jié)果即可,具體代碼如下所示。
/// <summary> /// 企業(yè)付款(請(qǐng)求需要雙向證書) /// 企業(yè)付款業(yè)務(wù)是基于微信支付商戶平臺(tái)的資金管理能力,為了協(xié)助商戶方便地實(shí)現(xiàn)企業(yè)向個(gè)人付款, /// 針對(duì)部分有開發(fā)能力的商戶,提供通過(guò)API完成企業(yè)付款的功能。 比如目前的保險(xiǎn)行業(yè)向客戶退保、給付、理賠。 /// 企業(yè)付款將使用商戶的可用余額,需確??捎糜囝~充足。查看可用余額、充值、提現(xiàn)請(qǐng)登錄商戶平臺(tái)“資金管理”進(jìn)行操作。https://pay.weixin.qq.com/ /// 注意:與商戶微信支付收款資金并非同一賬戶,需要單獨(dú)充值。 /// </summary> /// <param name="json">企業(yè)支付數(shù)據(jù)</param> /// <returns></returns> public CorpPayResult CorpPay(CorpPayJson json) { CheckAccount();//檢查AccountInfo的對(duì)象屬性值 WxPayData data = new WxPayData(); data.SetValue("mch_appid", AccountInfo.UniteAppId);//公眾賬號(hào)appid, 注意是mch_appid,而非wxappid data.SetValue("mchid", AccountInfo.MchID);//商戶號(hào), 注意是mchid而非mch_id data.SetValue("nonce_str", data.GenerateNonceStr());//隨機(jī)字符串 data.SetValue("spbill_create_ip", NetworkUtil.GetIPAddress());//終端ip data.SetValue("partner_trade_no", data.GenerateOutTradeNo(AccountInfo.MchID));//隨機(jī)字符串 data.SetValue("device_info", json.device_info);//終端ip data.SetValue("openid", json.openid); data.SetValue("check_name", json.check_name); data.SetValue("re_user_name", json.re_user_name); data.SetValue("amount", json.amount); data.SetValue("desc", json.desc); data.SetValue("sign", data.MakeSign(AccountInfo.PayAPIKey));//最后生成簽名 var url = string.Format("https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"); return Helper.GetPayResultWithCert<CorpPayResult>(data, url, AccountInfo.CertPath, AccountInfo.CertPassword); }
接口定義及實(shí)現(xiàn)好后,我們可以在項(xiàng)目中對(duì)API進(jìn)行調(diào)用測(cè)試,具體代碼如下所示
CorpPayJson json = new CorpPayJson() { amount = 100, check_name = PayCheckName.FORCE_CHECK.ToString(), desc = "測(cè)試退款", openid = this.openId, device_info = "", re_user_name = "伍華聰", spbill_create_ip = NetworkUtil.GetIPAddress() }; var result = api.CorpPay(json); var message = string.Format("企業(yè)直接付款:{0} {1}", result.Success ? "成功" : "失敗", result.Message); Console.WriteLine(message); Console.WriteLine(result.ToJson());
付款操作成功后,我們可以看到這個(gè)錢是直接到用戶錢包里面去的,而且我們也可以在商戶后臺(tái)進(jìn)行記錄的查看,可以看到對(duì)應(yīng)的記錄。
?
?更多C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!
?

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
