ThinkPHP QR code payment interface and thinkphp payment Interface
I recently scanned the QR code and paid for it. I read the official documents and found many webpages. I found that they do not match the document/demo. Now I am able to figure it out (the file name has changed). I will post it and share it with you.
1. Place useful official lib files and related files in the vendor
2. Call the same payment Interface
WechatController
// Call the same payment Interface
Public function native ($ v_oid = '', $ v_amount = ''){
Ini_set ('date. timezone ', 'Asia/Shanghai ');
Error_reporting (E_ERROR );
// Add related class files
Vendor ('wxpay. WxPayApi ');
Vendor ('wxpay. log ');
Vendor ('wxpay. nativepa ');
// Initialize the log
$ LogHandler = new \ CLogFileHandler ("../logs/". date ('Y-m-d'). '. log ');
$ Log = \ Log: Init ($ logHandler, 15 );
// Accept order information
If (trim ($ v_oid) <> "") // determines whether there is an order number passed
{
$ V_oid = trim ($ v_oid );
}
Else
{
$ This-> error ('empty Order No. ', U ('user/Index '));
Exit;
}
$ V_amount = trim ($ v_amount * 100); // payment amount
// Call the same payment Interface
$ Notify = new \ NativePay ();
$ Input = new \ WxPayUnifiedOrder ();
// Product description ------------------------------ required parameter transmission/unified information
$ Input-> SetBody ("product description location ");
// Additional data
$ Input-> SetAttach ("additional data location ");
// Merchant Order Number
$ Input-> SetOut_trade_no ($ v_oid );
// Total amount
$ Input-> settotal_amount ($ v_amount );
// Start time
$ Input-> SetTime_start (date ("YmdHis "));
// End Time
$ Input-> SetTime_expire (date ("YmdHis", time () + 600 ));
// Product tag
$ Input-> SetGoods_tag ("Product tag location ");
// Asynchronous notification address, which cannot contain any parameters
$ Input-> setpolicy_url (U ('policyprocess '));
// Transaction type
$ Input-> SetTrade_type ("NATIVE ");
// Product id
$ Input-& gt; SetProduct_id ("123456789 ");
// Obtain the same payment interface result
$ Result = $ Y-> GetPayUrl ($ input );
$ Url2 = $ result ["code_url"];
$ This-> assign ('data', urlencode ($ url2 ));
$ This-> assign ('v _ id', $ v_oid); $ this-> assign ('v _ amount ', $ v_amount/100 ); $ this-> display ();} 3. generate QR code
3. Generate QR code for payment
Public function qrcode (){
Error_reporting (E_ERROR );
Vendor ('wxpay. phpqrcode. phpqrcode ');
$ Url = $ _ GET ["data"];
\ QRcode: png ($ url );
}
Iv. asynchronous Processing
Specific handling procedures and methods based on personal needs
// Asynchronous order query Mechanism
Public function Queryorder ($ transaction_id)
{
$ Input = new \ WxPayOrderQuery ();
$ Input-> SetTransaction_id ($ transaction_id );
$ Result = \ WxPayApi: orderQuery ($ input );
\ Log: DEBUG ("query:". json_encode ($ result ));
If (array_key_exists ("return_code", $ result)
& Array_key_exists ("result_code", $ result)
& $ Result ["return_code"] = "SUCCESS"
& $ Result ["result_code"] = "SUCCESS ")
{
Return true;
}
Return false;
}
5. display the QR code in another form.
<Form action = "" method = "post" id = "myForm-table">
<H2> Order Information <Div class = "orderNumber">
<P class = "a"> Order No.: "{$ v_oid}" </p>
<P class = "B">
<Span class = "left"> payable amount: <strong> <em >{$ v_amount }</em> RMB </strong> </span>
<Span class = "right"> after payment, the flight wing customer service will contact you. If you have any questions, please contact the 24-hour flight hotline 400-700-2016 </span>
</P>
</Div>
<H2> PAY
<Div class = "order-submit"> <a href = "javascript: history. go (-1); "class =" submitOrder Order "> other payment methods </a> </div>
</Form>
The successful graph is not attached. This is a problem I encountered. Due to the need for reconstruction, it is messy and there are too many invalid code. I need to sort it out, record it, and share it with me.