主頁 > 知識庫 > php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能

php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能

熱門標(biāo)簽:萍鄉(xiāng)商鋪地圖標(biāo)注 桂陽公司如何做地圖標(biāo)注 太原400電話申請流程 宿州正規(guī)外呼系統(tǒng)軟件 企業(yè)400電話辦理多少費(fèi)用 代理打電話機(jī)器人 神龍斗士電話機(jī)器人 電信外呼系統(tǒng)多少錢一個(gè)月 合肥企業(yè)外呼系統(tǒng)線路

本文實(shí)例為大家分享了php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶的具體代碼,供大家參考,具體內(nèi)容如下

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對應(yīng)的request類,類名稱和接口名稱對應(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í)際情況下請轉(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 訂單號
  * @param $pay_no  轉(zhuǎn)賬賬號
  * @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)入請求
  $request = new \AlipayFundTransToaccountTransferRequest ();
  $request->setBizContent("{" .
   "\"out_biz_no\":\"".$order_number."\"," .//商戶生成訂單號
   "\"payee_type\":\"ALIPAY_LOGONID\"," .//收款方支付寶賬號類型
   "\"payee_account\":\"".$pay_no."\"," .//收款方賬號
   "\"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;
 }
}
?>

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

您可能感興趣的文章:
  • PHP與以太坊交互詳解
  • php實(shí)現(xiàn)微信企業(yè)轉(zhuǎn)賬功能
  • 微信企業(yè)轉(zhuǎn)賬之入口類分裝php代碼
  • php實(shí)現(xiàn)微信公眾號企業(yè)轉(zhuǎn)賬功能
  • php7中停止php-fpm服務(wù)的方法詳解
  • PHP 對接美團(tuán)大眾點(diǎn)評團(tuán)購券(門票)的開發(fā)步驟
  • PHP小程序后臺部署運(yùn)行 LNMP+WNMP的方法
  • 為PHP模塊添加SQL SERVER2012數(shù)據(jù)庫的步驟詳解
  • php微信小程序解包過程實(shí)例詳解
  • 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算
  • PHP實(shí)現(xiàn)創(chuàng)建以太坊錢包轉(zhuǎn)賬等功能

標(biāo)簽:綏化 崇左 白銀 鄂州 辛集 太原 廊坊 衡陽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能》,本文關(guān)鍵詞  php,實(shí)現(xiàn),單筆,轉(zhuǎn)賬,到,支付,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能》相關(guān)的同類信息!
  • 本頁收集關(guān)于php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章