鄙人在做一个项目,需要用到支付宝进行支付,pc端的直接用立即下单很快就好了,生成二维码扫描支付,但是移动端我尝试了很多次就是换不起来,开始使用的方法错了,后来用对了, 但是还是换不起来,郁闷结果我发现是我的方法有问题,修改后就正常了,下面上代码,其实什么语言都一样;
require_once LIBRARY_PATH . 'alipay/alipay.config.php';
require_once LIBRARY_PATH . 'alipay/alipay_submit.class.php';
require_once LIBRARY_PATH .'aop/AopClient.php';
require_once LIBRARY_PATH .'aop/AopCertification.php';
require_once LIBRARY_PATH .'aop/request/AlipayTradeQueryRequest.php';
require_once LIBRARY_PATH .'aop/request/AlipayTradeWapPayRequest.php';
require_once LIBRARY_PATH .'aop/request/AlipayTradeAppPayRequest.php';
$parameter = array(
"product_code" => 'QUICK_MSECURITY_PAY',
"out_trade_no" => $orderId,
"subject" => "你的项目",
"total_amount" => '0.01',
"body" => $this->user['id']
);
$parameter = json_encode($parameter,JSON_NUMERIC_CHECK);
$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = C('applyId');
$aop->rsaPrivateKey = C('rsaPrivateKey');
$aop->alipayrsaPublicKey =C('alipayrsaPublicKey');
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$request = new AlipayTradewapPayRequest ();
$request->setBizContent($parameter);
$request->setNotifyUrl( "http://".C("SERVER_PATH")."/aliPayNotify.php");
$request->setReturnUrl("http://".C("SERVER_PATH")."/aliPayReturn.php");
$result = $aop->pageExecute($request);
echo json_encode(array("code"=>0,"data"=>$result));
exit();
上面就是具体的代码了,具体流程还是支付宝文档的流程:
1.引入配置文件
2.设置参数,如上面的$parameter
3.转成json
4.new一个AopClient ();对象
5.设置对象基本参数
6.调用支付宝方法 $request = new AlipayTradewapPayRequest (),并设置参数
7.将参数统一处理用到pageExecute();方法就可以了
剩下的就是返回前端了,直接ajax调用window.document.write=data.result就是了
下面是截图唤起效果