thinkphp WeChat Scan code payment interface, thinkphp payment Interface _php Tutorial

Source: Internet
Author: User

Thinkphp Scan Code Payment interface, thinkphp payment interface


Recently toss sweep code to pay, read the official documents, find a lot of pages, found and document/demo do not match, and now it is made out (the file name has changed), posted to share

I. Place useful official LIB files and related documents used in the vendor

Two. Calling the same payment interface

Wechatcontroller

//Call the same payment interface
Public functionNative$v _oid='',$v _amount=''){
Ini_set (' Date.timezone ',' Asia/shanghai ');
Error_reporting (E_ERROR);
//To add a related class file
Vendor' Wxpay.wxpayapi ');
Vendor' Wxpay.log ');
Vendor' Wxpay.nativepay ');
//Initialize Log
$logHandler= new \Clogfilehandler (".. /logs/".Date' y-m-d ').'. log ');
$log= \Log::Init ($logHandler,15);
//Accept Order Information
IfTrim$v _oid)<>"")//Determine if there is a delivery order number
{
$v _oid=Trim$v _oid);
}
Else
{
$this-Error'Order number is empty',U' User/index '));
Exit
}

$v _amount=Trim$v _amount*100);//Amount paid

//Call the same payment interface
$notify= new \Nativepay ();
$input= new \Wxpayunifiedorder ();
//Product Description----------------------------Parameter passing required/Unified information
$input-Setbody ("Product Description Location");
//Additional data
$input-Setattach ("Additional Data Locations");
//Merchant Order Number
$input-Setout_trade_no ($v _oid);
//Total Amount
$input-Settotal_fee ($v _amount);
//Start time
$input-Settime_start (Date"Ymdhis"));
//End time
$input-Settime_expire (Date"Ymdhis",Time ()+600));
//Commodity mark
$input-Setgoods_tag ("Product Mark Location");
//Asynchronous notification Address, cannot carry any parameters
$input -> setnotify_url ( U ( ' notifyprocess '));
// transaction type
$input -> settrade_type ( "NATIVE");
// product ID
$input -> setproduct_id ( "123456789");
// Get the same payment interface result
$result = $notify -> getpayurl ( $input);
$url 2 = $result [ "Code_url"];

$this -> Assign ( ' data ', urlencode ( $url 2));
$this -> assign (' v_oid ', $v _oid); $this->assign (' V_amount ', $v _amount/100); $this Display ();} Three. Generate QR code
three.  pay to generate two-dimensional code
QRCode () {
Error_reporting (e_error);
Vendor (' Wxpay.phpqrcode.phpqrcode ');
$_get["Data"];
\qrcode::png ($url);
}

Four. Asynchronous processing
Specific processing processes and methods according to individual needs

//Asynchronous query Order mechanism
Public functionQueryorder ($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;
}

/span>
span> five. One more form form showing QR code

<Formaction=""Method="POST"Id="Myform-table" >
<H2>Order Information H2>
<Divclass="OrderNumber" >
<Pclass="A" >Order Number:"{$v _oid}" P>
<Pclass="B" >
<Spanclass="Left" >Amount payable:<strong><Em>{$v _amount} Em>Yuan strong> span>
<span class="right" > after payment, Flight wing customer service will contact you, if you have any questions, please consult the Flight Hotline 400-700-2016 span>
P>
Div>
<h2> payment h2>
<img src="{: U (' QRCode ')}?data={$data}" alt=" sweep code >
<div class="Order-submit" ><a href="javascript:history. Go(-1); " class="SubmitOrder Order" > return to other payment methods a> div>
form>



The success of the diagram is not attached, this is my problem, because to refactor, so the more chaotic, invalid code is more, need to collate, record, share one or two


http://www.bkjia.com/PHPjc/1114481.html www.bkjia.com true http://www.bkjia.com/PHPjc/1114481.html techarticle thinkphp Scan Code Payment interface, thinkphp payment interface recently toss sweep code to pay, read the official documents, find a lot of pages, found and document/demo do not match, now oneself is sort of ...

  • 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.