码迷,mamicode.com
首页 > 其他好文 > 详细

支付宝支付

时间:2017-08-29 12:53:42      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:oba   elk   rdk   请求   spm   response   hsb   传输   form   

1、先申请支付注册签约开通APP支付等。
 
2、引入PHP SDK包
 
 
3、注意几个事项,编码转换,签名类型,对比签名,密钥
4、代码
//生成支付订单
function create(){
$total = input(‘total‘);
$aop = new AopClient;
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$aop->appId = "2017051707261724";
$aop->rsaPrivateKey = "MIICWwIBAAKBgQCuMno8RxNNxYAmtZylQyD0uEo0clUJsF+xHZ449EWgpfwOLeQwCjVg8Cy1peKnRlqeYdXI3iz/b3elQNgcD3hi5ERWfKlJJlbLrIUhSBbb12n6jgyat9yoRv0hNP+pexI16eyNvo/xo+1+ufyxRKdnAy3P8EDeWSCwkY4jkfn2nwIDAQABAoGAYXq50HVtpf25gu/qYsi37noafFLmp29dfT23xuNa+1UnQcAIi6GK0V5Vhqj3tue12h+hhLBfuelkqMMqrDk0AiZD3jRC7xOu0q3nOX/8X2NOJjgCtzYs3r1U9Fsi6pGMgLx3Go/lDEN3mLJ/QlGrtHZ2RVc0PpkLaLRVj9BiGWECQQDfj/JSr47HDit49OBaWNnhMAh9/19Si8h5YcURVql/W1Xgr75t1VHwF0YMKCF0I1TEFoXIODZnYUXsyVWvzFunAkEAx3jmnPocDUrX0PyUedODARAtk6BJed2e/tlSAMqCDZ5fMtseXl8Ybqlrfu+ncZiQmtm5Rj97TXFHjEBtLVgMSQI/Bhzpg1lJjifVCHmpqM7FJmMp2EgjUx5/XNJPkSnNeK4Gqx4jFt2+X9JDGBIA2CwfJT14awEee7UtNExNC4GLAkB+iLYZnBrRX8m5m5AAG+k9cmrG++XANZLXbTo0oEGRrAYNt6vzB3XzNOuo0ROx3qrUYArEgh6QiKxvTqszGWhpAkEAtfj9qJJw4OBdYJ+jfjdLp2wUoR7ORD9H65luUVardoKIyAwvkY53zMftegSG6AupzbwpaQdWcwnHCd3cO6YIQw==";
//私钥
$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA";//签名类型
//支付宝公钥
$aop->alipayrsaPublicKey = ‘MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB‘;
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
$request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$bizcontent = "{\"body\":\"我是测试数据\","
. "\"subject\": \"App支付测试\","
. "\"out_trade_no\": \"20170125test03\","
. "\"timeout_express\": \"30m\","
. "\"total_amount\": $total,"
. "\"product_code\":\"QUICK_MSECURITY_PAY\""
. "}";
$request->setNotifyUrl(url(‘notify_url‘));
$request->setBizContent($bizcontent);
//这里和普通的接口调用不同,使用的是sdkExecute
$response = $aop->sdkExecute($request);
//htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
// echo htmlspecialchars($response);//就是orderString 可以直接给客户端请求,无需再做处理。
echo $response;//就是orderString 可以直接给客户端请求,无需再做处理。
}
 
//异步通知\
function notify_url(Request $request){
$aop = new AopClient;
$aop->alipayrsaPublicKey = ‘MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB‘;
$flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
trace($request,‘异步通知‘);
// echo ‘success‘;
}

支付宝支付

标签:oba   elk   rdk   请求   spm   response   hsb   传输   form   

原文地址:http://www.cnblogs.com/pangxiaox/p/7447324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!