Asp.Net Core3.0 微信转账到零钱
参考文档:
微信付款到零钱开发文档:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
用于向微信用户个人付款,目前支持向指定微信用户的openid付款。
1.付款转账
接口调用请求说明
请求url:https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
是否需要证书:是(证书及使用说明详见 商户证书)
请求方式:POST
代码只是简单实现转账功能,仅供参考,请勿在生产环境使用,否则可能造成资金风险。
/// <summary> /// 微信转账 /// </summary> /// <param name="inputData"></param> /// <param name="timeOut"></param> /// <returns></returns> public static WxPayData Transfers(WxPayData inputData, int timeOut = 6) { var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; inputData.SetValue("nonce_str", WxPayApi.GenerateNonceStr());//随机字符串 inputData.SetValue("sign", inputData.MakeSign());//签名 string xml = inputData.ToXml(); var start = DateTime.Now; string response = HttpService.Post(xml, url, true, timeOut); var end = DateTime.Now; int timeCost = (int)((end - start).TotalMilliseconds); WxPayData result = new WxPayData(); result.FromXml(response); ReportCostTime(url, timeCost, result);//测速上报 return result; }
//转账
public class TransfersPay
{
public string openid { get; set; }
public int amount { get; set; }
public string partner_trade_no { get; set; }
public string re_user_name { get; set; }
public string spbill_create_ip { get; set; }
public WxPayData GetTransfersApiParameters()
{
WxPayData apiParam = new WxPayData();
apiParam.SetValue("mch_appid", _appid);//公众账号ID
apiParam.SetValue("mchid", _mchid);//商户号
apiParam.SetValue("partner_trade_no", partner_trade_no);
apiParam.SetValue("openid", openid);
apiParam.SetValue("check_name", "NO_CHECK");
apiParam.SetValue("amount", amount);
apiParam.SetValue("desc", "提现");
//apiParam.SetValue("spbill_create_ip", spbill_create_ip);
//apiParam.SetValue("re_user_name", re_user_name);
return apiParam;
}
}