Home > Net >  Within [WeChat jsApi pay] WeChat H5 tuning up when payment, prompt "payment verification signat
Within [WeChat jsApi pay] WeChat H5 tuning up when payment, prompt "payment verification signat

Time:10-02

Unified order has passed, is also set up sign_type MD5, and obtain the prepay_id, js, and then to pass parameters to the delivering is suggested to verify signatures fails, exclude please,
C # the back-end code:

WxPayData data=https://bbs.csdn.net/topics/new WxPayData ();

//string device_info="gotophi. Cn";
//data. SetValue (" device_info, "device_info);//device number

String S_body="GoTopHi";
Data. The SetValue (" body ", S_body);//commodity description
//data. SetValue (" attach ", "WXpay");//additional data
Data. The SetValue (" out_trade_no ", strProductID);//merchant order number
Data. SetValue (" total_fee total_amout);//total amount, the unit is "points", must be an integer,

Data. The SetValue (" notify_url ", "http://www.gotophi.com/WX_pay/");//asynchronous receive WeChat pay result notification callback address

Data. The SetValue (" trade_type ", "the JSAPI");//transaction type
Data. The SetValue (" openid, "s_openid);//user id

String nonceStr=GenerateNonceStr ();
Data. The SetValue (" nonce_str, "nonceStr);//random string

//terminal IP
String spbill_create_ip=GetLoginIp ();
Data. The SetValue (" spbill_create_ip, "spbill_create_ip);

String appid=WxPayConfig. GetConfig (.) GetAppID ();

String McH_id=WxPayConfig. GetConfig (.) GetMchID ();


WxPayData result=WxPayApi. UnifiedOrder (data);//call the unified order interface

String S_return_code=result. GetValue (" return_code "). The ToString ();
//return the Content (S_return_code);
If (S_return_code=="SUCCESS")
{

String timeStamp=ConvertDateTimeInt (DateTime. Now). The ToString ();
The codebehind (categories.aspx.cs) [" timeStamp "]=timeStamp;

String prepay_id=result. GetValue (" prepay_id "). The ToString ();
The codebehind (categories.aspx.cs) [" prepay_id "]=prepay_id;

String S_return_code_appid=result. GetValue (" appid "). The ToString ();
The codebehind (categories.aspx.cs) [" appid "]=S_return_code_appid;

String S_return_code_nonceStr=result. GetValue (" nonce_str "). The ToString ();
//string S_return_code_nonceStr=nonceStr;
The codebehind (categories.aspx.cs) [" nonceStr "]=S_return_code_nonceStr;

String S_key=WxPayConfig. GetConfig (.) GetKey ();


//string S_return_code_appid pay_stringA="appId=" + + "& amp; TimeStamp="+ timeStamp +" & amp; S_return_code_nonceStr nonceStr="+ +" & amp; Package=prepay_id="+ prepay_id +" & amp; SignType=MD5 ";
String S_return_code_appid pay_stringA="appId=" + + "& amp; TimeStamp="+ timeStamp +" & amp; S_return_code_nonceStr nonceStr="+ +" & amp; Package=prepay_id="+ prepay_id +" & amp; SignType=HMAC - SHA256 ";
String pay_SignTemp=pay_stringA + "& amp; Key="+ S_key;
The codebehind (categories.aspx.cs) [" S_sign "]=pay_SignTemp + "* * *" + s_openid;

//return the Content (pay_SignTemp);

String S_paySign=MakeSign (pay_stringA S_key);

The codebehind (categories.aspx.cs) [" S_paySign "]=S_paySign;


}
The else
{
Response. Redirect ("/error/? S_err="+ HttpUtility. UrlEncode (" payment failure,"));
The Response. The End ();
}

The front-end JS code:
The function onBridgeReady () {
WeixinJSBridge. Invoke (
'getBrandWCPayRequest' {
"AppId" : "@ the codebehind (categories.aspx.cs) [" appId"] ",//the public name, by merchants to
"TimeStamp" : "@ the codebehind (categories.aspx.cs) [" timeStamp"] ",//timeStamp, since 1970 the number of seconds to
"NonceStr" : "@ the codebehind (categories.aspx.cs) [" nonceStr"] ",//random string
"Package" : "prepay_id=@ the codebehind (categories.aspx.cs) [" prepay_id"] ",
"SignType" : "HMAC - SHA256",//WeChat signature:
"PaySign" : "@ the codebehind (categories.aspx.cs) [" S_paySign"] "//WeChat signature
},
The function (res) {
If (res) err_msg=="get_brand_wcpay_request: ok") {
//use the above way to judge the front return, WeChat team solemnly tip:
//res. Err_msg will be paid by the user after a successful return ok, but does not guarantee it absolutely reliable,
}
});
}

If (typeof WeixinJSBridge=="undefined") {
If (document. AddEventListener) {
Document. The addEventListener (' WeixinJSBridgeReady onBridgeReady, false);
{} else if (document. AttachEvent)
Document. The attachEvent (' WeixinJSBridgeReady 'onBridgeReady);
Document. The attachEvent (' onWeixinJSBridgeReady 'onBridgeReady);
}
} else {
OnBridgeReady ();
}
</script>

Interface debugging tool https://pay.weixin.qq.com/wiki/tools/signverify/also tested the second signature Sign is right, don't understand, why always prompt "verify signature failure",

NonceStr numerical is unified to order the returned string,

Key is also no problem, do NATIVE payment is successful,

Please everybody teach... .

CodePudding user response:

Please everybody teach...
  •  Tags:  
  • C#
  • Related