页面
wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '<%=AppId %>', // 必填,公众号的唯一标识 timestamp: "<%=Timer %>", // 必填,生成签名的时间戳 nonceStr: "<%=RdCode %>", // 必填,生成签名的随机串 signature: "<%=GetSignature() %>", // 必填,签名,见附录1 jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function () { wx.chooseWXPay({ appId: '<%=AppId %>', timestamp: '<%=Timer %>', nonceStr: '<%=RdCode %>', package: 'prepay_id=<%=prepay_id%>', signType: 'MD5', paySign: '<%=paySign %>', success: function (res) { }, cancel: function () { }, error: function (e) { } }); }); 后台
public void GetprepayIdAndpaySign()
{
//公众账号ID
string appid = AppId;
//商品描述
string OrderCode = DateTime.Now.ToString("yyyyMMddHHmmss");
string body = "订单号:" + OrderCode;
//商户号
string mch_id = "1262625001";
//随机字符串
string nonce_str = RdCode;
//通知地址-接收微信支付成功通知
string notify_url = "http://a.k-bean.com/notify_url.aspx";
//用户标识 -用户在商户appid下的唯一标识
string openid = OpenId;
//商户订单号
string out_trade_no = OrderCode;
//下单IP
string spbill_create_ip = GetIP(this.Context);
//总金额 分为单位
int total_fee = 1;
//交易类型 -JSAPI、NATIVE、APP 如果是生成二维码请填写NATIVE
string trade_type = "JSAPI";
//微信签名
string tmpStr = "appid=" + appid + "&body=" + body + "&mch_id=" + mch_id + "&nonce_str=" + nonce_str + "¬ify_url=" + notify_url + "&openid=" + openid + "&out_trade_no=" + out_trade_no + "&spbill_create_ip=" + spbill_create_ip + "&total_fee=" + total_fee + "&trade_type=" + trade_type + "&key=" + key + "";
string Getprepay_idSign = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "MD5").ToUpper();
string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
string xml = "<xml>";
xml += "<appid>" + appid + "</appid>";
xml += "<body>" + body + "</body>";
xml += "<mch_id>" + mch_id + "</mch_id>";
xml += "<nonce_str>" + nonce_str + "</nonce_str>";
xml += "<notify_url>" + notify_url + "</notify_url>";
xml += "<openid>" + openid + "</openid>";
xml += "<out_trade_no>" + out_trade_no + "</out_trade_no>";
xml += "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>";
xml += "<total_fee>" + total_fee + "</total_fee>";
xml += "<trade_type>" + trade_type + "</trade_type>";
xml += "<sign>" + Getprepay_idSign + "</sign>";
xml += "</xml>";
string v = PostWebRequests(url, xml);
//获取的prepay_id
prepay_id = v;
//获取paySign,请对照前后台的大小写
string v_tmpStr = "appId=" + appid + "&nonceStr=" + RdCode + "&package=prepay_id=" + v + "&signType=MD5&timeStamp=" + Timer + "&key=" + key + "";
paySign = FormsAuthentication.HashPasswordForStoringInConfigFile(v_tmpStr, "MD5").ToUpper();
}