/// <summary> /// 提现转账到零钱 /// </summary> /// <param name="inputData"></param> /// <param name="certPathName">证书地址 最好不要放到网站目录</param> /// <param name="certPwd">默认是商户号(坑) 不是管理证书的密码</param> /// <returns></returns> public async Task <TransfersReturnModel> SubmitTransfersToWechatAccount(TransfersPayModel inputData, string certPathName, string certPwd) { var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; PackageParamModel packageParam = inputData.GetApiParameters(); packageParam.AddValue("mch_appid", this.AppId); //公众账号ID? packageParam.AddValue("mchid", this._mchId); //商户号 packageParam.AddValue("nonce_str", WechatCommonUtlis.GetNonceStr()); //随机字符串 packageParam.AddValue("sign", WechatCommonUtlis.GetMD5Sign(packageParam, this._appKey)); //签名 string xmlPackage = packageParam.ToXml(); string response = await WebHelper.HttpPostCertAsync(url, xmlPackage, certPathName, certPwd, 10); //证书默认密码为微信商户号 //这里会有一个错 The SSL connection could not be established 1证书导入计算机且配置商户号的ip.2.证书路径读取权限 3.发起的web请求可能与版本有关 本人装了2.1后莫名其解决了 PackageParamModel newResult = new PackageParamModel(); newResult.FromXml(response); if (newResult.GetValue("result_code").ToString().ToUpper() == "SUCCESS") { TransfersReturnModel transfersReturnModel = new TransfersReturnModel { partner_trade_no = newResult.GetValue("partner_trade_no").ToString(), payment_no = newResult.GetValue("payment_no").ToString(), payment_time = newResult.GetValue("payment_time").ToDate(), }; return(transfersReturnModel); } throw new WxPayException(newResult.GetValue("err_code_des").ToString()); }
public async Task <PayBankReturnModel> SubmitPayBank(PayBankModel inputData, string pubkey, string certFilePath, string certPwd) { string url = "https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank"; PackageParamModel packageParam = inputData.GetApiParameters(pubkey); packageParam.AddValue("mch_id", this._mchId); packageParam.AddValue("nonce_str", WechatCommonUtlis.GetNonceStr()); packageParam.AddValue("sign", WechatCommonUtlis.GetMD5Sign(packageParam, this._appKey)); string xmlPackage = packageParam.ToXml(); string response = await WebHelper.HttpPostCertAsync(url, xmlPackage, certFilePath, certPwd, 10);//证书默认密码为微信商户号 PackageParamModel newResult = new PackageParamModel(); newResult.FromXml(response); if (newResult.GetValue("result_code").ToString().ToUpper() == "SUCCESS") { PayBankReturnModel model = new PayBankReturnModel { partner_trade_no = newResult.GetValue("partner_trade_no").ToString(), payment_no = newResult.GetValue("payment_no").ToString(), cmms_amt = (newResult.GetValue("cmms_amt").ToInt() / 100).ToDecimal(2), }; return(model); } throw new WxPayException(newResult.GetValue("err_code_des").ToString()); }
/// <summary> /// 获取RSA加密公钥API /// </summary> /// <returns></returns> public async Task <string> GetPublicKey(string certPathName, string certPwd) { string url = "https://fraud.mch.weixin.qq.com/risk/getpublickey"; PackageParamModel packageParam = new PackageParamModel(); packageParam.AddValue("mch_id", this._mchId); packageParam.AddValue("nonce_str", WechatCommonUtlis.GetNonceStr()); packageParam.AddValue("sign_type", this._signType); packageParam.AddValue("sign", WechatCommonUtlis.GetMD5Sign(packageParam, this._appKey)); //签名 string xmlPackage = packageParam.ToXml(); string response = await WebHelper.HttpPostCertAsync(url, xmlPackage, certPathName, certPwd, 10); //证书默认密码为微信商户号 PackageParamModel newResult = new PackageParamModel(); newResult.FromXml(response); if (newResult.GetValue("result_code").ToString().ToUpper() == "SUCCESS") { return(newResult.GetValue("pub_key").ToString()); } throw new WxPayException(newResult.GetValue("err_code_des").ToString()); }
private string GetPrepayId(string xmlResult) //处理微信支付返回的Xml 获取prepay_id { PackageParamModel packageParam = new PackageParamModel(); packageParam.FromXml(xmlResult); string prepay_id = packageParam.GetValue("prepay_id").ToString(); if (prepay_id.IsNullOrEmpty()) { throw new WxPayException("为获取到支付prepay_id"); } return(prepay_id); }
/// <summary> /// 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。 /// </summary> /// <param name="transaction_id">商户订单号out_trade_no二选一</param> /// <returns></returns> public async Task <bool> QueryOrder(string transaction_id) { string url = " https://api.mch.weixin.qq.com/pay/orderquery"; PackageParamModel packageDic = new PackageParamModel(); packageDic.AddValue("appid", this.AppId); //应用ID packageDic.AddValue("mch_id", this._mchId); //商户号 packageDic.AddValue("transaction_id", transaction_id); //商户号 packageDic.AddValue("nonce_str", WechatCommonUtlis.GetNonceStr()); packageDic.AddValue("sign_type", this._signType); packageDic.AddValue("sign", WechatCommonUtlis.GetMD5Sign(packageDic, this._appKey));//签名 string xmlPackage = packageDic.ToXml(); string response = await WebHelper.HttpPostAsync(url, xmlPackage, null, 10); PackageParamModel newResult = new PackageParamModel(); newResult.FromXml(response); if (newResult.GetValue("return_msg").ToString() == "OK") { return(true); } return(false); }