佳木斯湛栽影视文化发展公司

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

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

熱門標(biāo)簽:團(tuán)購網(wǎng)站 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 銀行業(yè)務(wù) 阿里云 服務(wù)器配置 科大訊飛語音識(shí)別系統(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對(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;
 }
}
?>

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

您可能感興趣的文章:
  • PHP與以太坊交互詳解
  • php實(shí)現(xiàn)微信企業(yè)轉(zhuǎn)賬功能
  • 微信企業(yè)轉(zhuǎn)賬之入口類分裝php代碼
  • php實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能
  • php7中停止php-fpm服務(wù)的方法詳解
  • PHP 對(duì)接美團(tuán)大眾點(diǎn)評(píng)團(tuán)購券(門票)的開發(fā)步驟
  • PHP小程序后臺(tái)部署運(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)簽:江蘇 衢州 廣元 大理 棗莊 衡水 蚌埠 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能》,本文關(guān)鍵詞  ;如發(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)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    康定县| 固镇县| 阿尔山市| 雷山县| 静安区| 金堂县| 鹿泉市| 宜都市| 江津市| 噶尔县| 广安市| 桑日县| 民县| 桃江县| 元江| 山东省| 连南| 峡江县| 昌乐县| 海宁市| 上饶市| 黄龙县| 天气| 磐安县| 苏尼特右旗| 杨浦区| 崇礼县| 双鸭山市| 渭源县| 阜新市| 九江市| 陆良县| 中超| 手机| 屯门区| 秦皇岛市| 巴塘县| 比如县| 城步| 西贡区| 井陉县|