SdkPayment.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: king/QQ:995265288
  5. * Date: 2018/11/3
  6. * Time: 10:27 AM
  7. */
  8. namespace app\common\components\alipay\Wap2;
  9. use app\common\services\alipay\AopClient;
  10. use app\common\services\alipay\request\AlipayTradeAppPayRequest;
  11. use app\common\services\alipay\request\AlipayTradeWapPayRequest;
  12. class SdkPayment
  13. {
  14. /**
  15. * Request Mustf
  16. *
  17. * @var string
  18. */
  19. private $gateway_url = 'https://openapi.alipay.com/gateway.do';
  20. /**
  21. * Request Must
  22. *
  23. * @var string
  24. */
  25. private $app_id;
  26. /**
  27. * Request Must
  28. *
  29. * @var string
  30. */
  31. private $rsaPrivateKey;
  32. /**
  33. * Request Must
  34. *
  35. * @var string
  36. */
  37. private $alipayrsaPublicKey;
  38. /**
  39. * Request Must
  40. *
  41. * @var string
  42. */
  43. private $method;
  44. /**
  45. * Request Must
  46. *
  47. * @var string
  48. */
  49. private $charset = 'UTF-8';
  50. /**
  51. * Request Must
  52. *
  53. * @var string
  54. */
  55. private $sign_type = 'RSA2';
  56. /**
  57. * Request Must
  58. *
  59. * @var string
  60. */
  61. private $sign;
  62. /**
  63. * Request Must
  64. *
  65. * @var string
  66. */
  67. private $timestamp;
  68. /**
  69. * Request Must
  70. *
  71. * @var string
  72. */
  73. private $version = '1.0';
  74. /**
  75. * Request Must
  76. *
  77. * @var string
  78. */
  79. private $biz_content;
  80. /**
  81. * Request No
  82. *
  83. * @var string
  84. */
  85. private $format = 'JSON';
  86. /**
  87. * Request No
  88. *
  89. * @var string
  90. */
  91. private $return_url;
  92. /**
  93. * Request No
  94. *
  95. * @var string
  96. */
  97. private $notify_url;
  98. public function __construct()
  99. {
  100. }
  101. public function pageExecute($data)
  102. {
  103. $aopClient = new AopClient();
  104. $aopClient->gatewayUrl = $this->gateway_url;
  105. $aopClient->appId = $this->app_id;
  106. $aopClient->rsaPrivateKey = $this->rsaPrivateKey; //'请填写开发者私钥去头去尾去回车,一行字符串';
  107. $aopClient->alipayrsaPublicKey = $this->alipayrsaPublicKey; //'请填写支付宝公钥,一行字符串';
  108. $aopClient->apiVersion = $this->version;
  109. $aopClient->postCharset = $this->charset;
  110. $aopClient->format = $this->format;
  111. $aopClient->signType = $this->sign_type;
  112. $request = new AlipayTradeWapPayRequest();
  113. $request->setBizContent($data);
  114. $request->setNotifyUrl($this->notify_url);
  115. $request->setReturnUrl($this->return_url);
  116. $result = $aopClient->pageExecute($request, 'GET');
  117. \Log::info('-------test2-------', print_r($result,true));
  118. return $result;
  119. }
  120. public function sdkExecute($data)
  121. {
  122. $aopClient = new AopClient();
  123. $aopClient->gatewayUrl = $this->gateway_url;
  124. $aopClient->appId = $this->app_id;
  125. $aopClient->rsaPrivateKey = $this->rsaPrivateKey; //'请填写开发者私钥去头去尾去回车,一行字符串';
  126. $aopClient->alipayrsaPublicKey = $this->alipayrsaPublicKey; //'请填写支付宝公钥,一行字符串';
  127. $aopClient->apiVersion = $this->version;
  128. $aopClient->postCharset = $this->charset;
  129. $aopClient->format = $this->format;
  130. $aopClient->signType = $this->sign_type;
  131. $request = new AlipayTradeAppPayRequest();
  132. $request->setBizContent($data);
  133. $request->setNotifyUrl($this->notify_url);
  134. $request->setReturnUrl($this->return_url);
  135. $result = $aopClient->sdkExecute($request);
  136. \Log::info('-------test--tt-pay-------', print_r($result,true));
  137. return $result;
  138. }
  139. public function setAppId($app_id)
  140. {
  141. $this->app_id = $app_id;
  142. return $this;
  143. }
  144. public function setRsaPrivateKey($rsaPrivateKey)
  145. {
  146. $this->rsaPrivateKey = $rsaPrivateKey;
  147. return $this;
  148. }
  149. public function setAlipayrsaPublicKey($alipayrsaPublicKey)
  150. {
  151. $this->alipayrsaPublicKey = $alipayrsaPublicKey;
  152. return $this;
  153. }
  154. public function setMethod($method)
  155. {
  156. $this->method = $method;
  157. return $this;
  158. }
  159. public function setCharset($charset)
  160. {
  161. $this->charset = $charset;
  162. return $this;
  163. }
  164. public function setSignType($method)
  165. {
  166. $this->method = $method;
  167. return $this;
  168. }
  169. public function setSign($sign)
  170. {
  171. $this->sign = $sign;
  172. return $this;
  173. }
  174. public function setTimestamp($timestamp)
  175. {
  176. $this->timestamp = $timestamp;
  177. return $this;
  178. }
  179. public function setVersion($version)
  180. {
  181. $this->version = $version;
  182. return $this;
  183. }
  184. public function setBizContent($biz_content)
  185. {
  186. $this->biz_content = $biz_content;
  187. return $this;
  188. }
  189. public function setFormat($format)
  190. {
  191. $this->format = $format;
  192. return $this;
  193. }
  194. public function setReturnUrl($return_url)
  195. {
  196. $this->return_url = $return_url;
  197. return $this;
  198. }
  199. public function setNotifyUrl($notify_url)
  200. {
  201. $this->notify_url = $notify_url;
  202. return $this;
  203. }
  204. }