欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂PHP開發(fā)培訓(xùn)之支付寶APP支付功能源碼講解

2018-07-26 13:29:06 1223瀏覽

今天扣丁學(xué)堂PHP培訓(xùn)資料給大家分享了php支付寶APP支付功能,首先用Android九宮格圖片展示的具體代碼,下面我們一起來看一下吧。


支付寶網(wǎng)頁支付

1.支付寶開放平臺(tái)添加應(yīng)用,獲得appid,并簽約。

2.在支付寶開放品臺(tái)設(shè)置如下:



3.配置支付寶的應(yīng)用公鑰。(根據(jù)支付寶的文檔)

4.在開放平臺(tái)下載官方sdkdemo。

5.代碼:

//支付寶
 include_once VENDOR_PATH . 'Alipay/aop/AopClient.php';
 include_once VENDOR_PATH . 'Alipay/aop/request/AlipayTradeAppPayRequest.php';
 $notify_url='http://m.dionly.net.cn/app/pay/AlipayStep3Notify';
 $config = array(
  'appid' =>$this->appid,//
  'rsaPrivateKey' =>$this->rsaPrivateKey,//開發(fā)者私鑰私鑰
  'alipayrsaPublicKey'=>$this->alipayrsaPublicKey,//支付寶公鑰
  'charset'=>strtolower('utf-8'),//編碼
  'notify_url' =>$notify_url,//回調(diào)地址(支付寶支付成功后回調(diào)修改訂單狀態(tài)的地址)
  'payment_type' =>1,//(固定值)
  'seller_id' =>'',//收款商家賬號(hào)
  'charset' => 'utf-8',//編碼
  'sign_type' => 'RSA2',//簽名方式
  'timestamp' =>date("Y-m-d H:i:s"),
  'version' =>"1.0",//固定值
  'url'  => 'https://openapi.alipay.com/gateway.do',//固定值
  'method' => 'alipay.trade.app.pay',//固定值
 );
   
    $aop = new \AopClient();
    $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
    $aop->appId = $config['appid'];
    $aop->rsaPrivateKey = $config['rsaPrivateKey'];
    $aop->format = "json";
    $aop->charset = "UTF-8";
    $aop->signType = "RSA2";
    $aop->alipayrsaPublicKey=$config['alipayrsaPublicKey'];
   //實(shí)例化具體API對(duì)應(yīng)的request類,類名稱和接口名稱對(duì)應(yīng),當(dāng)前調(diào)用接口名稱:alipay.trade.app.pay
    $request = new \AlipayTradeAppPayRequest();
   //SDK已經(jīng)封裝掉了公共參數(shù),這里只需要傳入業(yè)務(wù)參數(shù)
     
    $bizcontent = json_encode([
      'body'=>'**',
      'subject'=>$subject,
      'out_trade_no'=> $order_sn,//此訂單號(hào)為商戶唯一訂單號(hào)
      'total_amount'=>$totalprice,//保留兩位小數(shù)
      'product_code'=>'QUICK_MSECURITY_PAY'
    ]);
    $request->setNotifyUrl($config['notify_url']);
    $request->setBizContent($bizcontent);
   //這里和普通的接口調(diào)用不同,使用的是sdkExecute
    $response = $aop->sdkExecute($request);
   //htmlspecialchars是為了輸出到頁面時(shí)防止被瀏覽器將關(guān)鍵參數(shù)html轉(zhuǎn)義,實(shí)際打印到日志以及http傳輸不會(huì)有這個(gè)問題
   $datas=$response;//就是orderString 可以直接給客戶端請(qǐng)求,無需再做處理。
   $this->arr['code']=0;
   $this->arr['msg']=$order_sn;
   $this->arr['info']=$datas;
   echo json_encode($this->arr);exit;

6.支付回調(diào)notify_url。

include_once VENDOR_PATH . 'Alipay/aop/AopClient.php';
   $aop = new \AopClient();
   $config['alipayrsaPublicKey']=$this->$alipayrsaPublicKey;//公鑰
   $aop->alipayrsaPublicKey = $config['alipayrsaPublicKey'];
   //此處驗(yàn)簽方式必須與下單時(shí)的簽名方式一致
   $flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
   //驗(yàn)簽通過后再實(shí)現(xiàn)業(yè)務(wù)邏輯,比如修改訂單表中的支付狀態(tài)。
   /**
   ①驗(yàn)簽通過后核實(shí)如下參數(shù)out_trade_no、total_amount、seller_id
   ②修改訂單表
    **/
   $out_trade_no = I('post.out_trade_no'); //商戶訂單號(hào)

之后對(duì)數(shù)據(jù)庫對(duì)應(yīng)的數(shù)據(jù)進(jìn)行修改。

7、訂單查詢接口:

include_once VENDOR_PATH . 'Alipay/aop/SignData.php';
  include_once VENDOR_PATH . 'Alipay/aop/AopClient.php';
  include_once VENDOR_PATH . 'Alipay/aop/request/AlipayTradeQueryRequest.php';
  $config = array(
   'appid' =>$this->appid,//
   'rsaPrivateKey' =>$this->rsaPrivateKey,//開發(fā)者私鑰私鑰
   'alipayrsaPublicKey'=>$this->alipayrsaPublicKey,//支付寶公鑰
   'charset'=>strtolower('utf-8'),//編碼
   'notify_url' =>'',//回調(diào)地址(支付寶支付成功后回調(diào)修改訂單狀態(tài)的地址)
   'payment_type' =>1,//(固定值)
   'seller_id' =>'',//收款商家賬號(hào)
   'charset' => 'utf-8',//編碼
   'sign_type' => 'RSA',//簽名方式
   'timestamp' =>date("Y-m-d H:i:s"),
   'version' =>"1.0",//固定值
   'url'  => 'https://openapi.alipay.com/gateway.do',//固定值
   'method' => 'alipay.trade.query',//固定值
  );
    
     $aop = new \AopClient();
     $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
     $aop->appId = $config['appid'];
     $aop->rsaPrivateKey = $config['rsaPrivateKey'];
     $aop->format = "json";
     $aop->charset = "UTF-8";
     $aop->signType = "RSA2";
     $aop->method = $config['method'];
     $aop->apiVersion = '1.0';
     $aop->alipayrsaPublicKey=$config['alipayrsaPublicKey'];
    //實(shí)例化具體API對(duì)應(yīng)的request類,類名稱和接口名稱對(duì)應(yīng),當(dāng)前調(diào)用接口名稱:alipay.trade.query
     $request = new \AlipayTradeQueryRequest();
  
     $bizcontent = json_encode([
       'out_trade_no'=>$order_sn,
       'trade_no'=>''
     ]);
      
     $request->setBizContent($bizcontent);
     
     $response = $aop->execute($request);
  
     $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
     $resultCode = $response->$responseNode->code;
     if(!empty($resultCode)&&$resultCode == 10000){
   
       $this->arr['code']=0;
       $this->arr['msg']='success';
       echo json_encode($this->arr);exit;
     
     } else {
       $this->arr['code']=100001;
       $this->arr['msg']='未查詢到訂單信息';
        echo json_encode($this->arr);exit;
      
 }

以上就是關(guān)于扣丁學(xué)堂PHP開發(fā)培訓(xùn)之支付寶APP支付功能源碼的講解,希望可以幫助到大家,

扣丁學(xué)堂微信公眾號(hào)



【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】

 


查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>

標(biāo)簽: PHP培訓(xùn) PHP視頻教程 PHP從入門到精通 PHP學(xué)習(xí)路線圖 PHP開發(fā)工程師

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費(fèi)咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號(hào)中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號(hào)-2   Copyright ? 2017 - 2022
返回頂部 返回頂部