123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- namespace app\common\library;
- use think\Controller;
- require_once env('root_path').'application/common/library/huiju/kuaijie/entity/Request.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/entity/Response.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/entity/NotifyResponse.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/entity/SecretKey.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/entity/Callback.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/exceptions/SDKException.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/AESUtil.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/HttpUtil.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/MD5Util.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/RandomUtil.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/RequestUtil.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/RSAUtil.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/SignUtil.php';
- require_once env('root_path').'application/common/library/huiju/kuaijie/utils/ObjectUtil.php';
- use joinpay\Request;
- use joinpay\SecretKey;
- use joinpay\RequestUtil;
- use joinpay\RandomUtil;
- use joinpay\AESUtil;
- class HuijuKjPay extends Controller
- {
- public function __construct(){
- $this->mch_no_trade = "888117500004672";
- //平台公钥
- $this->platPublicKey = "-----BEGIN PUBLIC KEY-----
- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCS4CHpmFRfFJR2cMjx2Ii7WBck6W3QXjr8ubrrlKkGVwMCpZT+Dg85jhsCqoTdVYJlbwfqpXNs5+I4KJ1K4cTz/9DgAjQW2oJF7owsGqPVbsz5APh5mWtlil71UNLwLWhlmmS2NcdcI/PdCH8/IY11q55Ymt+R55cst4ZSl62cTQIDAQAB
- -----END PUBLIC KEY-----";
- //商户私钥
- $this->mchPrivateKey = "-----BEGIN RSA PRIVATE KEY-----
- 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=
- -----END RSA PRIVATE KEY-----";
- }
- //短信
- public function sms($name,$id_card_no,$bank_card_no,$mobile){
- $secKey = RandomUtil::randomStr();
- $mch_order_no = get_order_sn();
- $data = [];
- // $data["mch_no_trade"] = $this->mch_no_trade;
- $data["mch_order_no"] = $mch_order_no;
- $data["order_amount"] = "0.01";
- $data["mch_req_time"] = date('Y-m-d H:i:s', time());
- $data["order_desc"] = "签约发送短信";
- $data["id_type"] = "1";
- $data["callback_param"] =null;
- $data["payer_name"] = AESUtil::encryptECB($name, $secKey);//加密
- $data["id_no"] = AESUtil::encryptECB($id_card_no, $secKey);//加密
- $data["bank_card_no"] = AESUtil::encryptECB($bank_card_no, $secKey);//加密
- $data["mobile_no"] = AESUtil::encryptECB($mobile, $secKey);//加密
- $request = new Request();
- $request->setMethod("fastPay.agreement.signSms");
- $request->setVersion("1.0");
- $request->setMchNo($this->mch_no_trade);
- $request->setSignType("2");
- $request->setRandStr(RandomUtil::randomStr(32));
- $request->setData($data);
- $request->setSecKey($secKey);//rsa有效
- $secretKey = new SecretKey();
- $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
- $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
- $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
- $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
- $url = "https://api.joinpay.com/fastpay";
- try {
- $response = RequestUtil::doRequest($url, $request, $secretKey);
- $res['resp_codo'] = $response->getRespCode();
- $res['biz_code'] = $response->getBizCode();
- $res['biz_msg'] = $response->getBizMsg();
- $res['data'] = $response->getData();
- $res['secKey'] = $secKey;
- $res['mch_order_no'] = $mch_order_no;
- return $res;
- } catch (Exception $e) {
- print_r($e);die;
- }
- }
- //签约
- public function signing($secKey,$mch_order_no,$sms_code){
- $data = [];
- //$data["mch_no_trade"] = "888117500004672";
- $data["mch_order_no"] = $mch_order_no;
- $data["sms_code"] = $sms_code;
- $request = new Request();
- $request->setMethod("fastPay.agreement.smsSign");
- $request->setVersion("1.0");
- $request->setMchNo($this->mch_no_trade);
- $request->setSignType("2");
- $request->setRandStr(RandomUtil::randomStr(32));
- $request->setData($data);
- $request->setSecKey($secKey);//rsa有效
- $secretKey = new SecretKey();
- $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
- $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
- $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
- $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
- $url = "https://api.joinpay.com/fastpay";
- try {
- $response = RequestUtil::doRequest($url, $request, $secretKey);
- $res['resp_codo'] = $response->getRespCode();
- $res['biz_code'] = $response->getBizCode();
- $res['biz_msg'] = $response->getBizMsg();
- $res['data'] = $response->getData();
- return $res;
- } catch (Exception $e) {
- print_r($e);
- }
- }
- //支付发送短信
- public function paySms($order_no,$money,$desc,$mid,$callback_url,$bank_card_no){
- $secKey = RandomUtil::randomStr(16);
- $data = [];
- // $data["mch_order_no"] = '202206251446464089001232';
- $data["mch_order_no"] = $order_no;
- $data["order_amount"] = $money;
- $data["mch_req_time"] = date('Y-m-d H:i:s', time());
- $data["order_desc"] = $desc;
- $data["callback_url"] = $callback_url;
- $data["callback_param"] =$mid;
- $data["bank_card_no"] = AESUtil::encryptECB($bank_card_no, $secKey);//加密
- $request = new Request();
- $request->setMethod("fastPay.agreement.paySms");
- $request->setVersion("1.0");
- $request->setMchNo($this->mch_no_trade);
- $request->setSignType("2");
- $request->setRandStr(RandomUtil::randomStr(32));
- $request->setData($data);
- $request->setSecKey($secKey);//rsa有效
- $secretKey = new SecretKey();
- $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
- $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
- $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
- $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
- $url = "https://api.joinpay.com/fastpay";
- try {
- $response = RequestUtil::doRequest($url, $request, $secretKey);
- $res['resp_codo'] = $response->getRespCode();
- $res['biz_code'] = $response->getBizCode();
- $res['biz_msg'] = $response->getBizMsg();
- $res['data'] = $response->getData();
- $res['secKey'] = $secKey;
- $res['mch_order_no'] = $order_no;
- return $res;
- } catch (Exception $e) {
- print_r($e);
- }
- }
- //支付
- public function kuaijiePay($order_no,$sms_code){
- $secKey = RandomUtil::randomStr(16);
- $data = [];
- $data["mch_order_no"] = $order_no;
- $data["mch_req_time"] = date('Y-m-d H:i:s', time());
- $data["sms_code"] = $sms_code;
- $request = new Request();
- $request->setMethod("fastPay.agreement.smsPay");
- $request->setVersion("1.0");
- $request->setMchNo($this->mch_no_trade);
- $request->setSignType("2");
- $request->setRandStr(RandomUtil::randomStr(32));
- $request->setData($data);
- $request->setSecKey($secKey);//rsa有效
- $secretKey = new SecretKey();
- $secretKey->setReqSignKey($this->mchPrivateKey);//签名:使用商户私钥
- $secretKey->setRespVerifyKey($this->platPublicKey);//验签:使用平台公钥
- $secretKey->setSecKeyEncryptKey($this->platPublicKey);//sec_key加密:使用平台公钥
- $secretKey->setSecKeyDecryptKey($this->mchPrivateKey);//sec_key解密:使用商户私钥
- $url = "https://api.joinpay.com/fastpay";
- try {
- $response = RequestUtil::doRequest($url, $request, $secretKey);
- $res['resp_codo'] = $response->getRespCode();
- $res['biz_code'] = $response->getBizCode();
- $res['biz_msg'] = $response->getBizMsg();
- $res['data'] = $response->getData();
- return $res;
- } catch (Exception $e) {
- print_r($e);
- }
- }
- }
|