商户Native支付下单接口,微信后台系统返回链接参数code_url,
商户后台系统将code_url值生成二维码图片,用户使用微信客户端扫码后发起支付。
1.SDK与DEMO下载
https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1
2.拷贝business与lib文件夹
3.将下载的证书解压后拷贝到cert文件夹下
4.修改lib文件夹下的DemoConfig文件
public string GetAppID(){
return "绑定支付的APPID";
}
public string GetMchID(){
return "商户号";
}
public string GetKey(){
return "配置密钥时输入的字符串";
}
public string GetSSlCertPath(){
return "cert\\apiclient_cert.p12";
}
public string GetSSlCertPassword(){
return "证书密码";
}
public string GetNotifyUrl(){
return "支付回调方法";//最好是使用域名
}
5.调用API返回支付Url
NativePay nativePay = new NativePay();
//生成扫码支付模式二url
WxPayModel wxPayModel = new WxPayModel();
wxPayModel.body = data.body;
wxPayModel.attach = data.attach;
wxPayModel.total_fee = data.total_fee;
wxPayModel.goods_tag = data.goods_tag;
wxPayModel.trade_type = "NATIVE";
wxPayModel.product_id = data.product_id;
wxPayModel.out_trade_no = out_trade_no;
string url = nativePay.GetPayUrl(wxPayModel);
6.根据url生成二维码
引用 qrcode.js,使用new QRCode生成二维码图片
new QRCode(document.getElementById("qrcode"), data.url);
7.支付结果回调
var buffer = new byte[Convert.ToInt32(Request.ContentLength)];
Request.Body.ReadAsync(buffer, 0, buffer.Length);
var body = Encoding.UTF8.GetString(buffer);//接收到的支付通知
//将xml格式的结果转换为对象以返回
WxPayData results = new WxPayData();
results.FromXml(body);
#region 更新订单状态
OrderNotify orderNotify = new OrderNotify();
orderNotify.return_code = results.GetValue("return_code").ToString();
if (orderNotify.return_code == "SUCCESS")
{
orderNotify.attach = results.GetValue("attach").ToString();
orderNotify.out_trade_no = results.GetValue("out_trade_no").ToString();
orderNotify.total_fee = Convert.ToDouble(results.GetValue("total_fee").ToString()) * 0.01;
orderNotify.transaction_id = results.GetValue("transaction_id").ToString();//微信订单号
}
else
{
msg = "[return_code]返回状态不为[SUCCESS]";
}
#endregion
8.支付结果查询
WxPayApi wxPayApi = new WxPayApi();
string transaction_id = data.transaction_id;//微信订单号
string out_trade_no = data.out_trade_no;//商户系统订单号
resultmsg = OrderQuery.Run(transaction_id, out_trade_no);//调用订单查询业务逻辑