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> /// 提现转账到零钱 /// </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()); }
/// <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()); }
} //必传 理赔 提现 转账等描述 public PackageParamModel GetApiParameters() { PackageParamModel apiParam = new PackageParamModel(); apiParam.AddValue("partner_trade_no", partner_trade_no); apiParam.AddValue("openid", openid); apiParam.AddValue("check_name", "NO_CHECK");//如果是FORCE_CHECK re_user_name必须为真实姓名 apiParam.AddValue("amount", amount); apiParam.AddValue("desc", desc); apiParam.AddValue("spbill_create_ip", spbill_create_ip); apiParam.AddValue("re_user_name", re_user_name); return(apiParam); }
} //操作描述 public PackageParamModel GetApiParameters(string publicKey) { PackageParamModel apiParam = new PackageParamModel(); apiParam.AddValue("partner_trade_no", partner_trade_no); apiParam.AddValue("enc_bank_no", SecurityHelper.RSAEncrypt(BankCardNo, publicKey)); apiParam.AddValue("enc_true_name", SecurityHelper.RSAEncrypt(RealName, publicKey)); apiParam.AddValue("bank_code", BankCode); apiParam.AddValue("desc", desc); apiParam.AddValue("amount", amount); return(apiParam); }
/// <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); }
private string CreatePayPackageAndGetPackageXml(PayInputModel payInput, string nonceStr) { int total_fee = Convert.ToInt32(payInput.TotalAmount * 100); //****************************************************************获取预支付订单编号*********************** PackageParamModel packageDic = new PackageParamModel(); packageDic.AddValue("appid", this.AppId); //应用ID packageDic.AddValue("mch_id", this._mchId); //商户号 packageDic.AddValue("nonce_str", nonceStr); //随机字符串 packageDic.AddValue("body", payInput.Body); //商品描述 String(128) 做二次支付的时候订单号不能重复 如果要重复 第二次和第一次的商品描述要一样 package.Add("detail",body);//商品详细 packageDic.AddValue("out_trade_no", payInput.OrderId); //商户订单号 packageDic.AddValue("total_fee", total_fee); //支付总金额 packageDic.AddValue("spbill_create_ip", WebHelper.GetRemoteIpAddress()); //终端IP packageDic.AddValue("notify_url", this._notifyUrl); //通知地址 packageDic.AddValue("trade_type", payInput.TradeType.GetEnumDescription()); //交易类型 小程序使用此类型 packageDic.AddValue("fee_type", "CNY"); //币种,人民币 packageDic.AddValue("attach", payInput.Attach); //自定义参数 if (payInput.TradeType == TradeType.JSAPI) { if (payInput.OpenId.IsNullOrEmpty())//用户标识JSAPI毕传 { throw new WxPayException("JSAPI必须指定OpenId"); } } if (!payInput.OpenId.IsNullOrEmpty()) { packageDic.AddValue("openid", payInput.OpenId); } var paySign = WechatCommonUtlis.GetMD5Sign(packageDic, this._appKey);//使用Md5签名 packageDic.AddValue("sign", paySign); return(packageDic.ToXml()); }
private PayReturnModel CreatePayReturnModel(TradeType tradeType, string nonceStr, string xmlResult) { string timeStamp = WechatCommonUtlis.GetTimestamp(); PackageParamModel packageDic = new PackageParamModel();//坑2 参数区分大小写 APP是小写 string prepay_id = GetPrepayId(xmlResult); string package; if (tradeType == TradeType.JSAPI) { packageDic.AddValue("appId", this.AppId);// 注意这里的大小写 应用AppID 坑4 packageDic.AddValue("timeStamp", timeStamp); packageDic.AddValue("nonceStr", nonceStr); package = string.Format("prepay_id={0}", prepay_id); packageDic.AddValue("package", package);//坑3 packageDic.AddValue("signType", this._signType); } else if (tradeType == TradeType.APP) { packageDic.AddValue("appid", this.AppId); packageDic.AddValue("partnerid", _mchId); packageDic.AddValue("prepayid", prepay_id); package = "Sign=WXPay"; packageDic.AddValue("package", package);//APP支付固定设置参数 packageDic.AddValue("timestamp", timeStamp); packageDic.AddValue("noncestr", nonceStr); } else { throw new WxPayException("暂未实现的支付类型"); } var paySign = WechatCommonUtlis.GetMD5Sign(packageDic, this._appKey);//坑1 APPKey可能也有错 PayReturnModel model = new PayReturnModel { timeStamp = timeStamp, nonceStr = nonceStr, package = package, paySign = paySign, signType = this._signType, appId = AppId, prepayId = prepay_id,//JSAPI支付忽略此字段 partnerId = _mchId }; return(model);//最终返回前端的参数 }