2018-07-26 13:29:06 1223瀏覽
今天扣丁學(xué)堂PHP培訓(xùn)資料給大家分享了php支付寶APP支付功能,首先用Android九宮格圖片展示的具體代碼,下面我們一起來看一下吧。2.在支付寶開放品臺(tái)設(shè)置如下:
//支付寶 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;
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)
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)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>