C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

高洛峰
Release: 2017-03-07 09:41:42
Original
2793 people have browsed it

1. 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.

C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

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


##Do you need a certificate


The request requires a two-way certificate. Detailed certificate use

Request parameters

C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

Example of submitted data:

<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>节日快乐!</desc>
<spbill_create_ip>10.2.3.10</spbill_create_ip>
<sign>C97BDBACF37622775366F38B629F45E3</sign>
</xml>
Copy after login

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>
Copy after login

According to the above interface description, as well as input and return parameters, we can build the corresponding C# code interface

C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

According to the above interface definition, we can define the interface information as follows Show

/// <summary>
    /// 微信支付接口
    /// </summary>
    public interface ITenPayApi
    {  

        /// <summary>
        /// 企业付款(请求需要双向证书)
        /// 企业付款业务是基于微信支付商户平台的资金管理能力,为了协助商户方便地实现企业向个人付款,
        /// 针对部分有开发能力的商户,提供通过API完成企业付款的功能。 比如目前的保险行业向客户退保、给付、理赔。
        /// 企业付款将使用商户的可用余额,需确保可用余额充足。查看可用余额、充值、提现请登录商户平台“资金管理”进行操作。https://pay.weixin.qq.com/ 
        /// 注意:与商户微信支付收款资金并非同一账户,需要单独充值。
        /// </summary>
        /// <param name="json">企业支付数据</param>
        /// <returns></returns>
        CorpPayResult CorpPay(CorpPayJson json);

        ..............
Copy after login

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.

C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

/// <summary>
    /// 企业付款的数据信息
    /// </summary>
    public class CorpPayJson
    {
        public CorpPayJson()
        {
            this.check_name = "FORCE_CHECK";
        }

        /// <summary>
        /// 微信支付分配的终端设备号
        /// </summary>
        public string device_info { get; set; }

        /// <summary>
        /// 用户openid
        /// </summary>
        public string openid { get; set; }

        /// <summary>
        /// 校验用户姓名选项,可以使用 PayCheckName枚举对象获取名称
        /// NO_CHECK:不校验真实姓名 
        /// FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账) 
        /// OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
        /// </summary>
        public string check_name { get; set; }

        /// <summary>
        /// 收款用户真实姓名。 
        /// 如果check_name设置为FORCE_CHECK或OPTION_CHECK,则必填用户真实姓名
        /// </summary>
        public string re_user_name { get; set; }

        /// <summary>
        /// 企业付款金额,单位为分
        /// </summary>
        public int amount { get; set; }

        /// <summary>
        /// 企业付款操作说明信息。必填。
        /// </summary>
        public string desc { get; set; }

        /// <summary>
        /// 调用接口的机器Ip地址
        /// </summary>
        public string spbill_create_ip { get; set; }
    }
Copy after login

/// <summary>
    /// 企业付款操作的返回结果
    /// </summary>
    public class CorpPayResult : PayResult
    {    
        /// <summary>
        /// 微信分配的公众账号ID(企业号corpid即为此appId)
        /// </summary>
        public string mch_appid { get; set; }

        /// <summary>
        /// 微信支付分配的终端设备号
        /// </summary>
        public string device_info { get; set; }

        /// <summary>
        /// 商户使用查询API填写的单号的原路返回. 
        /// </summary>
        public string partner_trade_no { get; set; }

        /// <summary>
        /// 企业付款成功,返回的微信订单号
        /// </summary>
        public string payment_no { get; set; }

        /// <summary>
        /// 企业付款成功时间
        /// </summary>
        public string payment_time { get; set; }
    }
Copy after login

企业付款的API实现和前面两种红包的处理方式 差不多,一个是传入常规的账号信息,一个是传入业务参数,然后提交获取结果即可,具体代码如下所示。

/// <summary>
        /// 企业付款(请求需要双向证书)
        /// 企业付款业务是基于微信支付商户平台的资金管理能力,为了协助商户方便地实现企业向个人付款,
        /// 针对部分有开发能力的商户,提供通过API完成企业付款的功能。 比如目前的保险行业向客户退保、给付、理赔。
        /// 企业付款将使用商户的可用余额,需确保可用余额充足。查看可用余额、充值、提现请登录商户平台“资金管理”进行操作。https://pay.weixin.qq.com/ 
        /// 注意:与商户微信支付收款资金并非同一账户,需要单独充值。
        /// </summary>
        /// <param name="json">企业支付数据</param>
        /// <returns></returns>
        public CorpPayResult CorpPay(CorpPayJson json)
        {
            CheckAccount();//检查AccountInfo的对象属性值

            WxPayData data = new WxPayData();
            data.SetValue("mch_appid", AccountInfo.UniteAppId);//公众账号appid, 注意是mch_appid,而非wxappid
            data.SetValue("mchid", AccountInfo.MchID);//商户号, 注意是mchid而非mch_id
            data.SetValue("nonce_str", data.GenerateNonceStr());//随机字符串
            data.SetValue("spbill_create_ip", NetworkUtil.GetIPAddress());//终端ip      
            data.SetValue("partner_trade_no", data.GenerateOutTradeNo(AccountInfo.MchID));//随机字符串

            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);
        }
Copy after login

接口定义及实现好后,我们可以在项目中对API进行调用测试,具体代码如下所示

CorpPayJson json = new CorpPayJson()
            {
                amount = 100,
                check_name = PayCheckName.FORCE_CHECK.ToString(),
                desc = "测试退款",
                openid = this.openId,
                device_info = "",
                re_user_name = "伍华聪",
                spbill_create_ip = NetworkUtil.GetIPAddress()
            };

            var result = api.CorpPay(json);
            var message = string.Format("企业直接付款:{0} {1}", result.Success ? "成功" : "失败", result.Message);
            Console.WriteLine(message);
            Console.WriteLine(result.ToJson());
Copy after login

C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

付款操作成功后,我们可以看到这个钱是直接到用户钱包里面去的,而且我们也可以在商户后台进行记录的查看,可以看到对应的记录。

C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation

 

 更多C# develops WeChat portal and applies WeChat payment enterprise payment packaging operation相关文章请关注PHP中文网!

 

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template