ThinkPHP微信掃碼支付介面,thinkphp支付介面_PHP教程

來源:互聯網
上載者:User

ThinkPHP掃碼支付介面,thinkphp支付介面


最近折騰掃碼支付,看了官方文檔,找了很多網頁,發現和文檔/demo不匹配,現在自己算是弄出來了(檔案名稱有所更改),貼出來分享一下

一.將有用的官方lib檔案和使用的相關檔案放置到vendor當中

二.調用同一支付介面

WechatController

//調用同一支付介面
public function native($v_oid='',$v_amount=''){
ini_set('date.timezone','Asia/Shanghai');
error_reporting(E_ERROR);
//添加相關的類檔案
vendor('Wxpay.WxPayApi');
vendor('Wxpay.log');
vendor('Wxpay.NativePay');
//初始化日誌
$logHandler= new \CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = \Log::Init($logHandler, 15);
//接受訂單資訊
if(trim($v_oid)<>"") //判斷是否有傳遞訂單號
{
$v_oid = trim($v_oid);
}
else
{
$this->error('訂單號為空白',U('User/index'));
exit;
}

$v_amount = trim($v_amount*100); //支付金額

//調用同一支付介面
$notify = new \NativePay();
$input = new \WxPayUnifiedOrder();
//商品描述----------------------------需要參數傳遞/統一資訊
$input->SetBody("商品描述位置");
//附加資料
$input->SetAttach("附加資料位元置");
//商戶訂單號
$input->SetOut_trade_no($v_oid);
//總金額
$input->SetTotal_fee($v_amount);
//開始時間
$input->SetTime_start(date("YmdHis"));
//結束時間
$input->SetTime_expire(date("YmdHis", time() + 600));
//商品標記
$input->SetGoods_tag("商品標記位置");
//非同步通知地址,不能攜帶任何參數
$input->SetNotify_url(U('NotifyProcess'));
//交易類型
$input->SetTrade_type("NATIVE");
//商品id
$input->SetProduct_id("123456789");
//擷取同一支付介面結果
$result = $notify->GetPayUrl($input);
$url2 = $result["code_url"];

$this->assign('data',urlencode($url2));
$this->assign('v_oid',$v_oid); $this->assign('v_amount',$v_amount/100); $this->display();}三.產生二維碼
三.支付產生二維碼
public function qrcode(){
error_reporting(E_ERROR);
vendor('Wxpay.phpqrcode.phpqrcode');
$url = $_GET["data"];
\QRcode::png($url);
}

四.非同步處理
具體處理流程和方式按個人需求

//非同步查詢訂單機制
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;
}

五.再來個form表單展示二維碼

<form action="" method="post" id="myForm-table">
<h2>訂單資訊h2>
<div class="orderNumber">
<p class="a">訂單號:"{$v_oid}"p>
<p class="b">
<span class="left">應付金額:<strong><em>{$v_amount}em>元strong>span>
<span class="right">付款後,飛行之翼客服會與您聯絡,如有問題請諮詢24小時飛行熱線 400-700-2016span>
p>
div>
<h2>支付h2>
<img src="{:U('qrcode')}?data={$data}" alt="掃碼">
<div class="order-submit"><a href="javascript:history.go(-1);" class="submitOrder Order">返回其他支付方式a>div>
form>



成功的圖就不附上了,這是我遇到的問題,由於要重構,所以比較亂,無效代碼也比較多,需要整理,記錄下來,分享一二
 


http://www.bkjia.com/PHPjc/1114481.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1114481.htmlTechArticleThinkPHP掃碼支付介面,thinkphp支付介面 最近折騰掃碼支付,看了官方文檔,找了很多網頁,發現和文檔/demo不匹配,現在自己算是弄...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.