# 代码示例
<?php | |
// +---------------------------------------------------------------------- | |
// | Quotes [没有目标的人生就是张拼图,反之则是蓝图] | |
// +---------------------------------------------------------------------- | |
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | |
// +---------------------------------------------------------------------- | |
// | Author: 云影 <8711973@qq.com> | |
// +---------------------------------------------------------------------- | |
// | Date: 2018 年 12 月 16 日 | |
// +---------------------------------------------------------------------- | |
// 支付宝转账操作类 | |
class Alit | |
{ | |
private $appId = '';//APPID | |
private $rsaPrivateKey = '';// 私钥 | |
private $rsaPublicKey = '';// 支付宝公钥 | |
private $payerName = '云影在线转账小程序';// 转账者名称 | |
private $Aop; | |
function __construct() | |
{ | |
// 引入支付宝文件 | |
include_once 'AopSdk.php'; | |
// 实例化 | |
$this->Aop = new \AopClient(); | |
// 配置信息 | |
$this->Aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; | |
$this->Aop->appId = $this->appId; | |
$this->Aop->rsaPrivateKey = $this->rsaPrivateKey; | |
$this->Aop->alipayrsaPublicKey=$this->rsaPublicKey; | |
$this->Aop->apiVersion = '1.0'; | |
$this->Aop->signType = 'RSA2'; | |
$this->Aop->postCharset='UTF-8'; | |
$this->Aop->format='json'; | |
} | |
/** | |
* 单笔转账到支付宝 | |
* @param unknown $orderId | |
* @param unknown $payAccount | |
* @param unknown $payAname | |
* @param unknown $payAmount | |
* @param unknown $payMemo | |
*/ | |
public function Transfer($orderId,$payAccount,$payName,$payAmount,$payMemo) | |
{ | |
// 导入请求 | |
$request = new \AlipayFundTransToaccountTransferRequest (); | |
$request->setBizContent("{" . | |
"\"out_biz_no\":\"".$orderId."\"," .// 商户生成订单号 | |
"\"payee_type\":\"ALIPAY_LOGONID\"," .// 收款方支付宝账号类型 | |
"\"payee_account\":\"".$payAccount."\"," .// 收款方账号 | |
"\"amount\":\"".$payAmount."\"," .// 总金额 | |
"\"payer_show_name\":\"".$this->payerName."\"," .// 付款方账户 | |
"\"payee_real_name\":\"".$payName."\"," .// 收款方姓名 | |
"\"remark\":\"".$payMemo."\"" .// 转账备注 | |
"}"); | |
$result = $this->Aop->execute($request); | |
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; | |
$resultCode = $result->$responseNode->code; | |
if(!empty($resultCode)&&$resultCode == 10000){ | |
return true; | |
} else { | |
return $result->$responseNode->sub_msg; | |
} | |
} | |
/** | |
* 查单 | |
* @param unknown $orderId 商户生成的订单号 | |
*/ | |
public function Query($orderId) | |
{ | |
// 导入请求 | |
$request = new \AlipayFundTransOrderQueryRequest (); | |
$request->setBizContent("{" . | |
"\"out_biz_no\":\"" . $orderId . "\"," . | |
" }"); | |
/*$request->setBizContent("{" . | |
"\"out_biz_no\":\"3142321423432\"," . | |
"\"order_id\":\"20160627110070001502260006780837\"" . | |
" }");*/ | |
$result = $this->Aop->execute($request); | |
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; | |
$resultCode = $result->$responseNode->code; | |
if(!empty($resultCode)&&$resultCode == 10000){ | |
$res_arr['code'] = '0'; | |
$res_arr['data'] = $result; | |
} else { | |
$res_arr['code'] = '-1'; | |
} | |
return $res_arr; | |
} | |
// 保存日志 自行发挥 | |
private function SaveLog() | |
{ | |
} | |
} |
请配合支付宝 SDK 食用
云影只是集成了转账和查单功能
附上官方 SDK 源码
源码