Custom parameters passed by WeChat payment

Source: Internet
Author: User
Hello, everyone, When I was developing a payment process, I encountered the following situation: After I obtained the merchant's order number, product price, and product name in a method for purchasing products, jump to the payment method, but because the method needs to get code, and get code needs to jump to the page, when... hello, everyone:
I encountered the following situation during the development of payment:

When I get the merchant's order number, product price, and product name in a method of purchasing a product, I will jump to the method of payment, but because the method needs to get the code, to get the code, you need to jump to the page. When the code is obtained, the page continues to jump back. However, at this time, the merchant's order number, product price, and product name passed by me are no longer available, therefore, this method is null, causing payment failure.

I hope you can help us with your ideas on solving this problem. Thank you.

Briefly paste the Code:

Function buyGoods () {// purchase method $ out_trade_no = "thinks"; $ body = "xiexie"; $ total_0000= "200"; wxPay ($ body, $ out_trade_no, $ total_pay);}/*** Payment Method */function wxPay ($ body, $ out_trade_no, $ total_fee) {$ jsApi = new JsApi_pub (); if (! Isset ($ _ GET ['code']) {// trigger return code $ url = $ jsApi-> createOauthUrlForCode (WxPayConf_pub: JS_API_CALL_URL); Header ("Location: $ url ") ;}else {// obtain the code to obtain openid $ code =$ _ GET ['code']; $ jsApi-> setCode ($ code ); $ openid = $ jsApi-> getOpenId () ;}$ unifiedOrder = new UnifiedOrder_pub (); $ unifiedOrder-> setParameter ("openid", "$ openid "); $ uniuniiedorder-> setParameter ("body", $ body); // product description // custom order number. For example, $ unigiedorder-> setParameter ("out_trade_no ", "$ out_trade_no"); // merchant's Order No. $ unifiedOrder-> setParameter ("total_eter", "$ total_eter"); // total amount $ unifiedOrder-> setParameter ("policy_url ", wxPayConf_pub: policy_url); // notification address $ unifiedOrder-> setParameter ("trade_type", "JSAPI"); // transaction type $ prepay_id = $ unifiedOrder-> getPrepayId (); $ jsApi-> setPrepayId ($ prepay_id); $ jsApiParameters = $ jsApi-> getParameters (); return $ jsApiParameters ;}

Reply content:

Hello, everyone:
I encountered the following situation during the development of payment:

When I get the merchant's order number, product price, and product name in a method of purchasing a product, I will jump to the method of payment, but because the method needs to get the code, to get the code, you need to jump to the page. When the code is obtained, the page continues to jump back. However, at this time, the merchant's order number, product price, and product name passed by me are no longer available, therefore, this method is null, causing payment failure.

I hope you can help us with your ideas on solving this problem. Thank you.

Briefly paste the Code:

Function buyGoods () {// purchase method $ out_trade_no = "thinks"; $ body = "xiexie"; $ total_0000= "200"; wxPay ($ body, $ out_trade_no, $ total_pay);}/*** Payment Method */function wxPay ($ body, $ out_trade_no, $ total_fee) {$ jsApi = new JsApi_pub (); if (! Isset ($ _ GET ['code']) {// trigger return code $ url = $ jsApi-> createOauthUrlForCode (WxPayConf_pub: JS_API_CALL_URL); Header ("Location: $ url ") ;}else {// obtain the code to obtain openid $ code =$ _ GET ['code']; $ jsApi-> setCode ($ code ); $ openid = $ jsApi-> getOpenId () ;}$ unifiedOrder = new UnifiedOrder_pub (); $ unifiedOrder-> setParameter ("openid", "$ openid "); $ uniuniiedorder-> setParameter ("body", $ body); // product description // custom order number. For example, $ unigiedorder-> setParameter ("out_trade_no ", "$ out_trade_no"); // merchant's Order No. $ unifiedOrder-> setParameter ("total_eter", "$ total_eter"); // total amount $ unifiedOrder-> setParameter ("policy_url ", wxPayConf_pub: policy_url); // notification address $ unifiedOrder-> setParameter ("trade_type", "JSAPI"); // transaction type $ prepay_id = $ unifiedOrder-> getPrepayId (); $ jsApi-> setPrepayId ($ prepay_id); $ jsApiParameters = $ jsApi-> getParameters (); return $ jsApiParameters ;}

I finally handled it like this:

$ JsApi = new JsApi_pub (); if (! Isset ($ _ GET ['code']) {// trigger return code $ url = $ jsApi-> createOauthUrlForCode (WxPayConf_pub: JS_API_CALL_URL ); $ state = json_encode (array ("body" => $ body, "out_trade_no" => $ out_trade_no, "total_fee" => "$ total_fee ",)); $ url = str_replace ("STATE", $ state, $ url); Header ("Location: $ url");} else {// get the code, obtain openid $ code =$ _ GET ['code']; $ jsApi-> setCode ($ code); $ openid = $ jsApi-> getOpenId (); $ state = $ _ GET ['state'];}

This parameter is included in the official URL.stateThe default value isSTATE, You only needSTATEReplace it with the content you need.

$ State = $ _ GET ['state']; then, how can we break down these three parameters! Please help me!

I also encountered this problem a few days ago during development and payment.
The link that originally obtained the code is
Const JS_API_CALL_URL = 'HTTP: // xxxxxx.cn /? C = WeixinBack & a = js_api_call_url ';
Only c can be obtained. a cannot be obtained.
Solution:
Const JS_API_CALL_URL = 'HTTP: // xxxxxx.cn /? C = WeixinBack | js_api_call_url |...
All parameters can be combined into a string with only one parameter.
Then rewrite a rule on the server to write the link in the original format.

How did you solve this problem? Now, I use thinkphp

The method I used first obtains the openId and saves it to the session before all services start.

Then start the business logic. At this time, because all your personal information is already in the session, there will be no jump problems.

Take a closer look at the payment documentation and find that the parameters can be passed ~ Another problem is found:
After the payment is complete, the location. href written in js cannot be redirected back to the successful payment page. Is this problem solved ??? What is the solution?

$ State = $ _ GET ['state']; then, how can we break down these three parameters?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.