濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > php支付寶APP支付功能

php支付寶APP支付功能

熱門標(biāo)簽:智能外呼電銷系統(tǒng) 哈爾濱400電話辦理到易號(hào)網(wǎng) h5 地圖標(biāo)注 高識(shí)別電銷機(jī)器人 拉薩打電話機(jī)器人 電銷機(jī)器人-快迭智能 寶安400電話辦理 沈陽人工智能電銷機(jī)器人公司 合肥外呼系統(tǒng)app

本文實(shí)例為大家分享了php支付寶APP支付的具體代碼,供大家參考,具體內(nèi)容如下

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

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

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

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

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

5.代碼:

 //支付寶
 include_once VENDOR_PATH . 'Alipay/aop/AopClient.php';
 include_once VENDOR_PATH . 'Alipay/aop/request/AlipayTradeAppPayRequest.php';
 $notify_url='https://www.www.com/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;
   
 }

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • php實(shí)現(xiàn)的支付寶網(wǎng)頁支付功能示例【基于TP5框架】
  • PHP支付寶當(dāng)面付2.0代碼
  • php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能
  • php app支付寶回調(diào)(異步通知)詳解
  • PHP實(shí)現(xiàn)QQ、微信和支付寶三合一收款碼實(shí)例代碼
  • PHP實(shí)現(xiàn)支付寶即時(shí)到賬功能
  • thinkPHP框架對(duì)接支付寶即時(shí)到賬接口回調(diào)操作示例
  • PHP接入支付寶接口失效流程詳解

標(biāo)簽:威海 巴中 梅州 林芝 張家口 成都 山東 泰州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php支付寶APP支付功能》,本文關(guān)鍵詞  php,支付,寶,APP,功能,php,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《php支付寶APP支付功能》相關(guān)的同類信息!
  • 本頁收集關(guān)于php支付寶APP支付功能的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    巨鹿县| 华池县| 朝阳区| 江西省| 马山县| 东平县| 广昌县| 顺平县| 涪陵区| 平舆县| 鄂温| 漳平市| 定结县| 赤壁市| 桃园市| 梅州市| 安远县| 张北县| 涞水县| 综艺| 大石桥市| 老河口市| 高碑店市| 潍坊市| 紫阳县| 富蕴县| 砚山县| 和硕县| 和静县| 波密县| 赫章县| 沂源县| 图木舒克市| 健康| 安远县| 库车县| 义乌市| 中山市| 贵南县| 东辽县| 莱西市|