//實(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;
}
}
?>