HuijuKjPay.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\common\library;
  3. use think\Controller;
  4. require_once env('root_path').'application/common/library/huiju/kuaijie/entity/Request.php';
  5. require_once env('root_path').'application/common/library/huiju/kuaijie/entity/Response.php';
  6. require_once env('root_path').'application/common/library/huiju/kuaijie/entity/NotifyResponse.php';
  7. require_once env('root_path').'application/common/library/huiju/kuaijie/entity/SecretKey.php';
  8. require_once env('root_path').'application/common/library/huiju/kuaijie/entity/Callback.php';
  9. require_once env('root_path').'application/common/library/huiju/kuaijie/exceptions/SDKException.php';
  10. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/AESUtil.php';
  11. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/HttpUtil.php';
  12. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/MD5Util.php';
  13. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/RandomUtil.php';
  14. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/RequestUtil.php';
  15. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/RSAUtil.php';
  16. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/SignUtil.php';
  17. require_once env('root_path').'application/common/library/huiju/kuaijie/utils/ObjectUtil.php';
  18. use joinpay\Request;
  19. use joinpay\SecretKey;
  20. use joinpay\RequestUtil;
  21. use joinpay\RandomUtil;
  22. use joinpay\AESUtil;
  23. class HuijuKjPay extends Controller
  24. {
  25. public function __construct(){
  26. $this->mch_no_trade = "888117500004672";
  27. //平台公钥
  28. $this->platPublicKey = "-----BEGIN PUBLIC KEY-----
  29. MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCS4CHpmFRfFJR2cMjx2Ii7WBck6W3QXjr8ubrrlKkGVwMCpZT+Dg85jhsCqoTdVYJlbwfqpXNs5+I4KJ1K4cTz/9DgAjQW2oJF7owsGqPVbsz5APh5mWtlil71UNLwLWhlmmS2NcdcI/PdCH8/IY11q55Ymt+R55cst4ZSl62cTQIDAQAB
  30. -----END PUBLIC KEY-----";
  31. //商户私钥
  32. $this->mchPrivateKey = "-----BEGIN RSA PRIVATE KEY-----
  33. MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKJ2zCsD/JMiFRRwGJvpf80NeWmduNGZ/sfU3mJRi00CYE5d9KbMpmq/A5gEurNiVkgFCOs+vF3F+qd+tla2+RuX/izTQlxlgHUh0W48BYm8FQYgL6YsJQj6sM8VeTSW7ynUAQdqU0kGe32QtFP829uggHhxj20yUsFM8nzDdX/rAgMBAAECgYANU7Fr1efiKemQw6FBKOZS68gJ4eZHS1qbCds0NXw31PoRc6OeCyublg+1aK3oCSkKv1777SmGh7cIBlzuwBOvDlMBTllA1xOrt0A//QLfWz0ELlEoGKJQZLxluYINbcoxjH7FvYxMlWWhYIJWr1JiK+OKV7A6NND9yxN9yzrIAQJBAM3g5ibq3xaUjdcFu2UXCXpm/DViNcwVymdbujzjRd1DLNhvvOMSZ3utgi6UJSiA3ryMRbBGITFUFXlaqXB2jucCQQDKBCab1sQmU2O5dshNpw4PkR0v4bR6/g16V6GEZ+NN4Vpg4rVexn5p7/Hyte+DKWSXfc5pKff0RWdxPwWruvpdAkEAhdLyx8lUSfE2YdawAP4Agzf+KRU1svtXHehaHsn8196af/Xh6hhEe/hE7tINdU6PejAT/IkZel8VtlRgX2IxcQJADnQnkwTVuexDeVSPVkb6kZCPZwqeECK3Mias7r1EHSFfhwkRcvt+tfOt+vCbd2XxxYkByLJxBDAnC4o3zKavHQJBAJIdMjx5OAxAswBFxL7smSDGbxfoeTAGrSlbyKpDXaw8qCxi3yMPHaljBr4yP/hqaA+4oSTZ84K4PqO7x3CJ0eA=
  34. -----END RSA PRIVATE KEY-----";
  35. }
  36. //短信
  37. public function sms(){
  38. $secKey = 'FbNzMFZMxmTxICn8';
  39. $data = [];
  40. // $data["mch_no_trade"] = $this->mch_no_trade;
  41. $data["mch_order_no"] = get_order_sn();
  42. $data["order_amount"] = "0.01";
  43. $data["mch_req_time"] = date('Y-m-d H:i:s', time());
  44. $data["order_desc"] = "测试sdk-php7";
  45. $data["id_type"] = "1";
  46. $data["callback_param"] =null;
  47. $data["payer_name"] = AESUtil::encryptECB("宋星伟", $secKey);//加密
  48. $data["id_no"] = AESUtil::encryptECB("371324199210037710", $secKey);//加密
  49. $data["bank_card_no"] = AESUtil::encryptECB("6217682503488661", $secKey);//加密
  50. $data["mobile_no"] = AESUtil::encryptECB("15801075991", $secKey);//加密
  51. dump($data);
  52. $request = new Request();
  53. $request->setMethod("fastPay.agreement.signSms");
  54. $request->setVersion("1.0");
  55. $request->setMchNo($this->mch_no_trade);
  56. $request->setSignType("2");
  57. $request->setRandStr(RandomUtil::randomStr(32));
  58. $request->setData($data);
  59. $request->setSecKey($secKey);//rsa有效
  60. $secretKey = new SecretKey();
  61. $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
  62. $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
  63. $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
  64. $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
  65. $url = "https://api.joinpay.com/fastpay";
  66. try {
  67. $response = RequestUtil::doRequest($url, $request, $secretKey);
  68. dump($response);die;
  69. } catch (Exception $e) {
  70. print_r($e);
  71. }
  72. }
  73. //签约
  74. public function signing(){
  75. $secKey = 'FbNzMFZMxmTxICn8';
  76. $data = [];
  77. $data["mch_no_trade"] = "888117500004672";
  78. $data["mch_order_no"] = "202206251510324416840933";
  79. $data["sms_code"] = "821991";
  80. $request = new Request();
  81. $request->setMethod("fastPay.agreement.smsSign");
  82. $request->setVersion("1.0");
  83. $request->setMchNo($this->mch_no_trade);
  84. $request->setSignType("2");
  85. $request->setRandStr(RandomUtil::randomStr(32));
  86. $request->setData($data);
  87. $request->setSecKey($secKey);//rsa有效
  88. $secretKey = new SecretKey();
  89. $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
  90. $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
  91. $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
  92. $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
  93. $url = "https://api.joinpay.com/fastpay";
  94. try {
  95. $response = RequestUtil::doRequest($url, $request, $secretKey);
  96. dump($response);die;
  97. } catch (Exception $e) {
  98. print_r($e);
  99. }
  100. }
  101. //支付
  102. public function kuaijiePay(){
  103. //$secKey = 'FbNzMFZMxmTxICn8';
  104. $secKey = RandomUtil::randomStr(16);
  105. $data = [];
  106. // $data["mch_order_no"] = '202206251446464089001232';
  107. $data["mch_order_no"] = get_order_sn();
  108. $data["order_amount"] = "0.02";
  109. $data["mch_req_time"] = date('Y-m-d H:i:s', time());
  110. $data["order_desc"] = "测试sdk-php7";
  111. $data["callback_url"] = 'https://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/kuaijiePayNotify';//回调地址
  112. $data["callback_param"] =null;
  113. $data["bank_card_no"] = AESUtil::encryptECB("6217682503488661", $secKey);//加密
  114. dump($data);
  115. $request = new Request();
  116. $request->setMethod("fastPay.agreement.pay");
  117. $request->setVersion("1.0");
  118. $request->setMchNo($this->mch_no_trade);
  119. $request->setSignType("2");
  120. $request->setRandStr(RandomUtil::randomStr(32));
  121. $request->setData($data);
  122. $request->setSecKey($secKey);//rsa有效
  123. $secretKey = new SecretKey();
  124. $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
  125. $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
  126. $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
  127. $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
  128. $url = "https://api.joinpay.com/fastpay";
  129. try {
  130. $response = RequestUtil::doRequest($url, $request, $secretKey);
  131. dump($response);
  132. } catch (Exception $e) {
  133. print_r($e);
  134. }
  135. }
  136. }