Home>Article>Backend Development> How to use php to implement Alipay payment
How to use php to implement Alipay payment: 1. Scan the code to log in to the Alipay open platform to register; 2. Find the development information and turn on the RSA2 key mode; 3. Check the Alipay private key and public key and other information; 4. Download the SDK for Alipay payment; 5. Just create a demo to implement Alipay payment.
The operating environment of this article: Windows 7 system, PHP version 7.4, DELL G3 computer
How to use php to implement Alipay payment?
Tips: Use the demo here For sandbox payment, you need to first register a sandbox account, etc.
Click to view and you can see that your Alipay private key, public key and other information should be saved and used later! ! !
For the settings of application gateway and authorization callback address, please view the documentAddress: https://developer.aliyun.com/article/707583
At this point our sandbox environment has been registered, now we start to complete a small payment demo!
Address: https://render.alipay.com/p/f/ fdjwq8nu2a/pages/home/index.html (here takes PHP language as an example)
'xxxx', //开发者私钥 'alipay_alipayrsapublicKey'=>'xxxx', //支付宝公钥 'alipay_notify'=>'http://www.xxx.com/xxx/xxx', //支付宝回调地址 支付成功后支付宝会把消息发送给此接口,在此接口中完成支付成功后的相关操作即可 ]; $aop = new AopClient(); // $aop->gatewayUrl = "https://openapi.alipaydev.com/gateway.do"; //网关地址要使用沙箱网关alipaydev $aop->gatewayUrl = "https://openapi.alipaydev.com/gateway.do"; //网关地址要使用沙箱网关alipaydev //支付宝分配给开发者的应用ID $aop->appId = $config['alipay_appid']; //请填写开发者私钥去头去尾去回车,一行字符串 $aop->rsaPrivateKey = $config['alipay_rsaprivateKey']; //请填写支付宝公钥,一行字符串 $aop->alipayrsaPublicKey = $config['alipay_alipayrsapublicKey']; 返回数据格式 $aop->format = "json"; // 表单提交字符集编码 $aop->postCharset = "utf-8"; //签名类型 $aop->signType = "RSA2"; //api版本 $aop->apiVersion = '1.0'; //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay $request = new AlipayTradeWapPayRequest(); //SDK已经封装掉了公共参数,这里只需要传入业务参数,沙箱环境的product_code只能是FAST_INSTANT_TRADE_PAY $info = [ 'body' => 'xxx', 'subject' => '标题', //订单标题。 'out_trade_no' => time().rand(1111,9999), //商户网站唯一订单号 自定义的订单号 'total_amount' => 1, //订单总金额。单位为元,精确到小数点后两位,取值范围:[0.01,100000000] 。 ]; $info = json_encode($info, JSON_UNESCAPED_UNICODE); //支付宝服务器主动通知商户服务器里指定的页面http/https路径。 支付回调 $request->setNotifyUrl($config['alipay_notify']); $request->setBizContent($info); //这里和普通的接口调用不同,使用的是sdkExecute $result = $aop->pageExecute($request); return $result; //$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; //$resultCode = $result->$responseNode->code; //if(!empty($resultCode)&&$resultCode == 10000){ // echo "成功"; //} else { // echo "失败"; //}
详细参数可查看文档 https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay?scene=21
At this time, accessing our demo.php file has been successfully invoked For Alipay payment, we can log in to the sandbox payment buyer account to complete the payment.
PHP Video Tutorial"
The above is the detailed content of How to use php to implement Alipay payment. For more information, please follow other related articles on the PHP Chinese website!