/**
* 支付宝参数配置
* @return AopClient
*/
public static function aliConfig(){
//需要包含的支付宝调用文件
require_once '/../library/alipaywap/aop/AopClient.php';
require_once '/../library/alipaywap/aop/request/AlipayTradePayRequest.php';
require_once '/../library/alipaywap/aop/request/AlipayTradeRefundRequest.php';
require_once '/../library/alipaywap/aop/request/AlipayFundAuthOperationCancelRequest.php';
require_once '/../library/alipaywap/aop/request/AlipayFundAuthOrderUnfreezeRequest.php';
require_once '/../library/alipaywap/aop/request/AlipayFundAuthOrderAppFreezeRequest.php';
require_once '/../library/alipaywap/aop/request/AlipayFundAuthOperationDetailQueryRequest.php';
$aop = new AopClient ();
$aop->appId = ''//支付宝appid
$aop->rsaPrivateKey = '';//商家私钥
$aop->alipayrsaPublicKey = '';//支付宝公钥
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
return $aop;
}
/**
* 资金冻结
* @param $out_order_no 商户授权资金订单号
* @param $out_request_no 商户本次资金操作的请求流水号
* @param $amount 需要冻结的金额
* @return string
*/
public function capitalFrozen($out_order_no,$out_request_no,$amount)
{
//调用配置、和方法
$aop = self::aliConfig();
$request = new AlipayFundAuthOrderAppFreezeRequest ();
// $path = APPLICATION_PATH.'/../public/ali/capital';
//
// //判断是否有这个路径
// if (!is_dir($path)){
// mkdir($path,0777,true);
// }
//
// $data = "out_order_no:".$out_order_no."------out_request_no:".$out_request_no."------".date('Y-m-d H:i:s')."\r\n";
// //写入日志
// file_put_contents($path."/".date('Y-m-d').".txt",$data);
//组装数据发送资金冻结请求
$request->setBizContent(
json_encode([
'out_order_no' =>$out_order_no, //商户授权资金订单号
'out_request_no' =>$out_request_no, //商户本次资金操作的请求流水号
'order_title' =>'测试预授权冻结', //业务订单的简单描述
'amount' =>$amount, //需要冻结的金额
'product_code' =>'PRE_AUTH_ONLINE', //销售产品码
'payee_user_id' =>'', //收款方的支付宝用户号ID
'pay_timeout' =>'90m', //该笔订单允许的最晚付款时间
'scene_code' =>'OVERSEAS_ONLINE_AUTH_COMMON_SCENE',//场景码
'trans_currency' =>'CNY', //标价币种 人民币
'settle_currency' =>'CNY', //商户指定的结算币种 人民币
'enable_pay_channels' =>[ //商户可用该参数指定用户可使用的支付渠道
// ['payChannelType' =>'PCREDIT_PAY'], //暂不支持花呗
['payChannelType' =>'MONEY_FUND'] //余额宝
]
])
);
$request->setNotifyUrl('url');//请求成功回调地址
$result = $aop->sdkExecute($request);
return $result;
}
请求成功会返回一串字符串示例:
之后小程序调用支付宝返回的orderStr唤起支付示例:
my.tradePay({
// 调用资金冻结接口(alipay.fund.auth.order.app.freeze),获取资金授权参数
orderStr: 'alipay_sdk=alipay-sdk-java-3.0.118.DEV&app_id=2018112803019836&biz_content=%7B%22amount%22%3A%220.02%22%2C%22extra_param%22%3A%22%7B%5C%22category%5C%22%3A%5C%22CHARGE_PILE_CAR%5C%22%7D%22%2C%22order_title%22%3A%22%D6%A7%B8%B6%B1%A6%D4%A4%CA%DA%C8%A8%22%2C%22out_order_no%22%3A%22ZMOutOrderNoAppFreeze2018052915543415090975%22%2C%22out_request_no%22%3A%22ZMOutReqNoAppFreeze20180529155434581875858%22%2C%22pay_timeout%22%3A%222d%22%2C%22payee_user_id%22%3A%222088202224929664%22%2C%22product_code%22%3A%22PRE_AUTH_ONLINE%22%7D&charset=GBK&format=json&method=alipay.fund.auth.order.app.freeze&sign=L4wk%2FNKcbJOo3n6Q5qbPzn0jUsvZlK4jr7iXnghudR0zeWJMmeNC71qIBSQfIz45n%2B5iTd0NQ5IK581xI2xCShTCiKAywnQcDmA%2Bjf%2BrRdKCDQCMLfCz%2BZ37C%2B6zxAX3e81%2F8Hr29lw4VPFfHkp9FmMwKw%2FGkNfV5ZlWoh7UtN8%3D&sign_type=RSA×tamp=2018-05-29+15%3A54%3A35&version=1.0',
success: (res) => {
my.alert({
content: JSON.stringify(res),
});
},
fail: (res) => {
my.alert({
content: JSON.stringify(res),
});
}
});
冻结成功返回参数:
{
"alipay_fund_auth_order_app_freeze_response" :{
"code" : "10000" ,
"msg" : "Success" ,
"auth_no" : "20140708000020***0000014417" ,
"out_order_no" : "4977***666634053" ,
"operation_id" : "201***0800032850551" ,
"out_request_no" : "20***70700166653" ,
"amount" : 0.02 ,
"status" : "SUCCESS" ,
"payer_user_id" : "208810****75885" ,
"gmt_trans" : "2014-09-15 11:23:04" ,
"pre_auth_type" : "CREDIT_AUTH" ,
"credit_amount" : 0.01 ,
"fund_amount" : 0.01
}
, "sign" : "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}