您好,登錄后才能下訂單哦!
本文章向大家介紹利用php怎么實(shí)現(xiàn)一個(gè)單筆轉(zhuǎn)賬到支付寶功能,主要包括利用php怎么實(shí)現(xiàn)一個(gè)單筆轉(zhuǎn)賬到支付寶功能的使用實(shí)例、應(yīng)用技巧、基本知識(shí)點(diǎn)總結(jié)和需要注意事項(xiàng),具有一定的參考價(jià)值,需要的朋友可以參考一下。
php是一個(gè)嵌套的縮寫名稱,指的是英文超級(jí)文本預(yù)處理語言(php:Hypertext Preprocessor)的縮寫,它的語法混合了C、Java、Perl以及php自創(chuàng)新的語法,主要用來做網(wǎng)站開發(fā),許多小型網(wǎng)站都用php開發(fā),因?yàn)閜hp是開源的,從而使得php經(jīng)久不衰。
1.首先 去螞蟻金服簽約 單筆轉(zhuǎn)賬到支付寶
官方api文檔
2.需要的配置信息
1).應(yīng)用appid
2).生成密鑰
文檔地址
根據(jù)文檔步驟生成
上傳這里的 應(yīng)用公鑰
3.下載官方sdk 然后集成到自己項(xiàng)目
服務(wù)端SDK
官方實(shí)例
//實(shí)例化客戶端 AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY, "RSA2"); //實(shí)例化具體API對(duì)應(yīng)的request類,類名稱和接口名稱對(duì)應(yīng),當(dāng)前調(diào)用接口名稱:alipay.open.public.template.message.industry.modify AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest(); //SDK已經(jīng)封裝掉了公共參數(shù),這里只需要傳入業(yè)務(wù)參數(shù) //此次只是參數(shù)展示,未進(jìn)行字符串轉(zhuǎn)義,實(shí)際情況下請(qǐng)轉(zhuǎn)義 request.setBizContent(" {" + " \"primary_industry_name\":\"IT科技/IT軟件與服務(wù)\"," + " \"primary_industry_code\":\"10001/20102\"," + " \"secondary_industry_code\":\"10001/20102\"," + " \"secondary_industry_name\":\"IT科技/IT軟件與服務(wù)\"" + " }"); AlipayOpenPublicTemplateMessageIndustryModifyResponse response = alipayClient.execute(request); //調(diào)用成功,則處理業(yè)務(wù)邏輯 if(response.isSuccess()){ //..... }
效果如下
我的代碼
<?php /** * create by 適可而止 * create time 2018/4/8 */ namespace Org\Util; class AlipayTransfer{ private $appId = 'appid'; private $rsaPrivateKey = '私鑰'; private $alipayrsaPublicKey = "支付寶公鑰"; private $payer_name = "xx科技"; private $aop; public function __construct() { $g_alipay = C('ALIPAY_CONFIG'); $this->appId = $g_alipay['APPID'];//appid $this->rsaPrivateKey = $g_alipay['rsaPrivateKey']; //私鑰 $this->alipayrsaPublicKey=$g_alipay['rsaPublicKey'];//支付寶公鑰 //引入單筆轉(zhuǎn)賬sdk Vendor('Alipayaop.AopSdk'); } public function init_aop_config() { $this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; $this->aop->appId = $this->appId; $this->aop->rsaPrivateKey = $this->rsaPrivateKey; $this->aop->alipayrsaPublicKey=$this->alipayrsaPublicKey; $this->aop->apiVersion = '1.0'; $this->aop->signType = 'RSA2'; $this->aop->postCharset='UTF-8'; $this->aop->format='json'; } /** * 單筆轉(zhuǎn)賬接口 * @param $order_number 訂單號(hào) * @param $pay_no 轉(zhuǎn)賬賬號(hào) * @param $pay_name 轉(zhuǎn)賬用戶名 * @param $amount 轉(zhuǎn)賬金額 * @param $memo 備注 */ public function transfer($order_number,$pay_no,$pay_name,$amount,$memo) { //存入轉(zhuǎn)賬日志 $this->transferLog($order_number,$pay_no,$pay_name,$amount); $this->aop = new \AopClient (); //配置參數(shù) $this->init_aop_config(); //導(dǎo)入請(qǐng)求 $request = new \AlipayFundTransToaccountTransferRequest (); $request->setBizContent("{" . "\"out_biz_no\":\"".$order_number."\"," .//商戶生成訂單號(hào) "\"payee_type\":\"ALIPAY_LOGONID\"," .//收款方支付寶賬號(hào)類型 "\"payee_account\":\"".$pay_no."\"," .//收款方賬號(hào) "\"amount\":\"".$amount."\"," .//總金額 "\"payer_show_name\":\"".$this->payer_name."\"," .//付款方賬戶 "\"payee_real_name\":\"".$pay_name."\"," .//收款方姓名 "\"remark\":\"".$memo."\"" .//轉(zhuǎn)賬備注 "}"); $result = $this->aop->execute ( $request); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $resultCode = $result->$responseNode->code; $resultSubMsg = $result->$responseNode->sub_msg; //修改轉(zhuǎn)賬日志 $this->edit_transferLog($order_number,$resultCode,$resultSubMsg); if(!empty($resultCode)&&$resultCode == 10000){ return true; } else { return false; } } /** * 存取日志 */ private function transferLog($order_number,$pay_no,$pay_name,$amount) { $data['order_number'] = $order_number; $data['pay_no'] = $pay_no; $data['pay_name'] = $pay_name; $data['amount'] = $amount; $data['create_time'] = time(); M('AlipayTransferLog')->add($data); } /** * 修改日志 */ private function edit_transferLog($order_number,$result_code,$sub_msg) { $model = D("AlipayTransferLog"); $where['order_number'] = $order_number; $result = $model->where($where)->order('create_time desc')->find(); if ($result_code == 10000) { $result['status'] = 1; $sub_msg = 'success'; } else { $result['status'] = 2; } $result['memo'] = $sub_msg; $result['update_time'] = time(); M('AlipayTransferLog')->save($result); } /** * 查單接口 */ public function query($order_number) { $this->aop = new \AopClient (); //配置參數(shù) $this->init_aop_config(); $request = new \AlipayFundTransOrderQueryRequest (); $request->setBizContent("{" . "\"out_biz_no\":\"".$order_number."\"" . " }"); $result = $this->aop->execute ( $request); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $resultCode = $result->$responseNode->code; if(!empty($resultCode)&&$resultCode == 10000){ $res_arr['code'] = '00'; $res_arr['data'] = $result; } else { $res_arr['code'] = '-1'; } return $res_arr; } } ?>
到此這篇關(guān)于利用php怎么實(shí)現(xiàn)一個(gè)單筆轉(zhuǎn)賬到支付寶功能的文章就介紹到這了,更多相關(guān)的內(nèi)容請(qǐng)搜索億速云以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持億速云!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。