HuijuKjPay.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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($name,$id_card_no,$bank_card_no,$mobile){
  38. $secKey = RandomUtil::randomStr();
  39. $mch_order_no = get_order_sn();
  40. $data = [];
  41. // $data["mch_no_trade"] = $this->mch_no_trade;
  42. $data["mch_order_no"] = $mch_order_no;
  43. $data["order_amount"] = "0.01";
  44. $data["mch_req_time"] = date('Y-m-d H:i:s', time());
  45. $data["order_desc"] = "签约发送短信";
  46. $data["id_type"] = "1";
  47. $data["callback_param"] =null;
  48. $data["payer_name"] = AESUtil::encryptECB($name, $secKey);//加密
  49. $data["id_no"] = AESUtil::encryptECB($id_card_no, $secKey);//加密
  50. $data["bank_card_no"] = AESUtil::encryptECB($bank_card_no, $secKey);//加密
  51. $data["mobile_no"] = AESUtil::encryptECB($mobile, $secKey);//加密
  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. $res['resp_codo'] = $response->getRespCode();
  69. $res['biz_code'] = $response->getBizCode();
  70. $res['biz_msg'] = $response->getBizMsg();
  71. $res['data'] = $response->getData();
  72. $res['secKey'] = $secKey;
  73. $res['mch_order_no'] = $mch_order_no;
  74. return $res;
  75. } catch (Exception $e) {
  76. print_r($e);die;
  77. }
  78. }
  79. //签约
  80. public function signing($secKey,$mch_order_no,$sms_code){
  81. $data = [];
  82. //$data["mch_no_trade"] = "888117500004672";
  83. $data["mch_order_no"] = $mch_order_no;
  84. $data["sms_code"] = $sms_code;
  85. $request = new Request();
  86. $request->setMethod("fastPay.agreement.smsSign");
  87. $request->setVersion("1.0");
  88. $request->setMchNo($this->mch_no_trade);
  89. $request->setSignType("2");
  90. $request->setRandStr(RandomUtil::randomStr(32));
  91. $request->setData($data);
  92. $request->setSecKey($secKey);//rsa有效
  93. $secretKey = new SecretKey();
  94. $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
  95. $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
  96. $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
  97. $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
  98. $url = "https://api.joinpay.com/fastpay";
  99. try {
  100. $response = RequestUtil::doRequest($url, $request, $secretKey);
  101. $res['resp_codo'] = $response->getRespCode();
  102. $res['biz_code'] = $response->getBizCode();
  103. $res['biz_msg'] = $response->getBizMsg();
  104. $res['data'] = $response->getData();
  105. return $res;
  106. } catch (Exception $e) {
  107. print_r($e);
  108. }
  109. }
  110. //支付发送短信
  111. public function paySms($order_no,$money,$desc,$mid,$callback_url,$bank_card_no){
  112. $secKey = RandomUtil::randomStr(16);
  113. $data = [];
  114. // $data["mch_order_no"] = '202206251446464089001232';
  115. $data["mch_order_no"] = $order_no;
  116. $data["order_amount"] = $money;
  117. $data["mch_req_time"] = date('Y-m-d H:i:s', time());
  118. $data["order_desc"] = $desc;
  119. $data["callback_url"] = $callback_url;
  120. $data["callback_param"] =$mid;
  121. $data["bank_card_no"] = AESUtil::encryptECB($bank_card_no, $secKey);//加密
  122. $request = new Request();
  123. $request->setMethod("fastPay.agreement.paySms");
  124. $request->setVersion("1.0");
  125. $request->setMchNo($this->mch_no_trade);
  126. $request->setSignType("2");
  127. $request->setRandStr(RandomUtil::randomStr(32));
  128. $request->setData($data);
  129. $request->setSecKey($secKey);//rsa有效
  130. $secretKey = new SecretKey();
  131. $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
  132. $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
  133. $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
  134. $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
  135. $url = "https://api.joinpay.com/fastpay";
  136. try {
  137. $response = RequestUtil::doRequest($url, $request, $secretKey);
  138. $res['resp_codo'] = $response->getRespCode();
  139. $res['biz_code'] = $response->getBizCode();
  140. $res['biz_msg'] = $response->getBizMsg();
  141. $res['data'] = $response->getData();
  142. $res['secKey'] = $secKey;
  143. $res['mch_order_no'] = $order_no;
  144. return $res;
  145. } catch (Exception $e) {
  146. print_r($e);
  147. }
  148. }
  149. //支付
  150. public function kuaijiePay($order_no,$sms_code){
  151. $secKey = RandomUtil::randomStr(16);
  152. $data = [];
  153. $data["mch_order_no"] = $order_no;
  154. $data["mch_req_time"] = date('Y-m-d H:i:s', time());
  155. $data["sms_code"] = $sms_code;
  156. $request = new Request();
  157. $request->setMethod("fastPay.agreement.smsPay");
  158. $request->setVersion("1.0");
  159. $request->setMchNo($this->mch_no_trade);
  160. $request->setSignType("2");
  161. $request->setRandStr(RandomUtil::randomStr(32));
  162. $request->setData($data);
  163. $request->setSecKey($secKey);//rsa有效
  164. $secretKey = new SecretKey();
  165. $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
  166. $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
  167. $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
  168. $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
  169. $url = "https://api.joinpay.com/fastpay";
  170. try {
  171. $response = RequestUtil::doRequest($url, $request, $secretKey);
  172. $res['resp_codo'] = $response->getRespCode();
  173. $res['biz_code'] = $response->getBizCode();
  174. $res['biz_msg'] = $response->getBizMsg();
  175. $res['data'] = $response->getData();
  176. return $res;
  177. } catch (Exception $e) {
  178. print_r($e);
  179. }
  180. }
  181. }