Blogger Information
Blog 10
fans 0
comment 0
visits 6998
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
快速实现支付宝支付及验签
礼物粑粑
Original
1054 people have browsed it

话不多说,直接上代码

首先,进入支付宝文档中心,下载通用版SDK

https://opendocs.alipay.com/open/02np93

  1. // Client
  2. public function createAopClient()
  3. {
  4. $aop = new \AopClient();
  5. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  6. $aop->appId = 'APPID';
  7. $aop->rsaPrivateKey = '私钥';
  8. $aop->alipayrsaPublicKey = '公钥';
  9. $aop->apiVersion = '1.0';
  10. $aop->signType = 'RSA2';
  11. $aop->postCharset = 'UTF-8';
  12. $aop->format = 'json';
  13. return $aop;
  14. }
  15. // 支付
  16. public function alipayTradeWapPayRequest(){
  17. $aop = $this->createAopClient();
  18. $request = new \AlipayTradeWapPayRequest();
  19. $info = [
  20. 'body' => 'xxx',
  21. 'subject' => '标题',
  22. // 商户网站唯一订单号,自定义的订单号
  23. 'out_trade_no' => time().rand(1111,9999),
  24. 'total_amount' => 1
  25. ];
  26. $info = json_encode($info, JSON_UNESCAPED_UNICODE);
  27. $request->setNotifyUrl('异步通知的URL');
  28. $request->setReturnUrl('同步返回URL');
  29. $request->setBizContent($info);
  30. //这里和普通的接口调用不同,使用的是sdkExecute
  31. $result = $aop->pageExecute($request);
  32. }
  33. // 回调验签
  34. public function checkSign($param = [])
  35. {
  36. $app = new \AopClient();
  37. $app->alipayrsaPublicKey = '公钥';
  38. $res = $app->rsaCheckV1($param, '私钥', 'RSA2');
  39. return $res;
  40. }

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post