app的支付宝接入代码及注意事项

//支付宝支付
public function alipay($money,$order_sn,$body)
{
vendor('aop.AopClient'); //官方sdk引入的文件
vendor('aop.request.AlipayTradeAppPayRequest');  //官方sdk引入的文件
$aop = new AopClient();
$aop->gatewayUrl="https://openapi.alipay.com/gateway.do";
$aop->appId="";
$aop->rsaPrivateKey=""; //私钥
$aop->format="json";
$aop->charset="UTF-8";
$aop->signType="RSA2";
$aop->alipayrsaPublicKey=""; //公钥
$request = new AlipayTradeAppPayRequest();
$bizcontent = json_encode([
'body'=>urlencode($body),
'subject'=>urlencode(''),   //标题
'out_trade_no'=>urlencode($order_sn),
'total_amount'=>urlencode($money),
'timeout_express'=>urlencode('30m'),
'product_code'=>urlencode('QUICK_MSECURITY_PAY')
]);
$request->setNotifyUrl(urlencode("http:/xxx")); //回调地址
$request->setBizContent($bizcontent);
$response = $aop->sdkExecute($request);
$str = $response;

if($str){
$this->success="成功";


return $str;
}else{
$this->error="失败";return false;
}

}

以上就是支付宝app接入的代码,跟官方的大致一样,但是官方的并没有加上urlencode的,虽然官方有提示我们。网上找的一些demo都没有加上urlencode的,所以我就写了个随笔

像上面加上urlencode填了参数便可以直接使用了

原文地址:https://www.cnblogs.com/doanddo/p/7493904.html