1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| <?php
class Payment_Kuaiqian { private $code = 'kuaiqian'; private $gatewaySandboxPC = 'https://sandbox.99bill.com/gateway/recvMerchantInfoAction.htm'; private $gatewaySandboxMobile = 'https://sandbox.99bill.com/mobilegateway/recvMerchantInfoAction.htm'; private $gatewayPC = 'https://www.99bill.com/gateway/recvMerchantInfoAction.htm'; private $gatewayMobile = 'https://www.99bill.com/mobilegateway/recvMerchantInfoAction.htm'; private $pcarduserPEMFile = 'certs/pcarduser.pem.php'; private $payParamStr = ''; private $signMsg = ''; private $payParamsOfPC = [ 'inputCharset' => '1', 'pageUrl' => '', 'bgUrl' => '', 'version' => 'v2.0', 'language' => '1', 'signType' => '4', 'signMsg' => '', 'merchantAcctId' => '', 'payerName' => '', 'payerContactType' => '', 'payerContact' => '', 'orderId' => '', 'orderAmount' => '', 'orderTime' => '', 'productName' => '', 'productNum' => '', 'productId' => '', 'productDesc' => '', 'ext1' => '', 'ext2' => '', 'payType' => '', 'bankId' => '', 'redoFlag' => '', 'pid' => '', ]; private $payParamsOfMobile = [ 'inputCharset' => '1', 'pageUrl' => '', 'bgUrl' => '', 'version' => 'mobile1.0', 'language' => '1', 'signType' => '4', 'merchantAcctId' => '', 'payerName' => '', 'payerContactType' => '1', 'payerContact' => '', 'payerIdType' => '3', 'payerId' => '', 'orderId' => '', 'orderAmount' => '', 'orderTime' => '', 'productName' => '', 'productNum' => '', 'productId' => '', 'productDesc' => '', 'ext1' => '', 'ext2' => '', 'payType' => '21', 'bankId' => '', 'redoFlag' => '0', 'pid' => '', ]; public function __construct($config) { date_default_timezone_set('Asia/Shanghai'); $this->payParamsOfPC['bgUrl'] = $this->payParamsOfMobile['bgUrl'] = $config['return_url']; $this->payParamsOfPC['pageUrl'] = $this->payParamsOfMobile['pageUrl'] = $config['notify_url']; $this->payParamsOfPC['productNum'] = $this->payParamsOfMobile['productNum'] = $config['goodsNum'] ? $config['goodsNum'] : 1; $this->payParamsOfPC['orderTime'] = $this->payParamsOfMobile['orderTime'] = date('YmdHis'); } public function kq_ck_null($kq_va, $kq_na) { if ($kq_va == "") { return $kq_va=""; } else { return $kq_va=$kq_na.'='.$kq_va.'&'; } } public function buildPayParams($isMobile) { $payParamsArr = $isMobile ? $this->payParamsOfMobile : $this->payParamsOfPC; $payParamStr = ''; foreach ($payParamsArr as $k => $v) { $payParamStr .= $this->kq_ck_null($v, $k); } $payParamStr = $isMobile ? rtrim($payParamStr, '&') : mb_substr($payParamStr, 0, mb_strlen($payParamStr)-1); $this->payParamStr = $payParamStr; return $this->payParamStr; } public function signPayParams() { $priv_key = trim(require_once __CORE_DIR.$this->pcarduserPEMFile);
$pkeyid = openssl_get_privatekey($priv_key); openssl_sign($this->payParamStr, $signMsg, $pkeyid, OPENSSL_ALGO_SHA1); openssl_free_key($pkeyid); $this->signMsg = base64_encode($signMsg); return $this->signMsg; } public function build_url($params) { if (!$params) { return false; } $isMobile = (!isset($params['gatewayType']) || (isset($params['gatewayType'])&&$params['gatewayType'] != 'pc')) ? true : false; $detail = K::M('payment/payment')->payment($this->code); if ($isMobile) { $gateway = $detail['kq_gateway_mobile'] ? $detail['kq_gateway_mobile'] : $this->gatewayMobile; $payParamsType = 'payParamsOfMobile'; } else { $gateway = $detail['kq_gateway_pc'] ? $detail['kq_gateway_pc'] : $this->gatewayPC; $payParamsType = 'payParamsOfPC'; } $payParamsTypeArr = &$this->$payParamsType; $payParamsTypeArr['merchantAcctId'] = $detail['config']['kq_merchant_id']; $payParamsTypeArr['productName'] = $params['title']; $payParamsTypeArr['productDesc'] = $params['body']; $payParamsTypeArr['payerName'] = $params['payerName']; $payParamsTypeArr['payerId'] = $params['uid']; $payParamsTypeArr['orderAmount'] = $params['amount']; $payParamsTypeArr['orderId'] = $params['trade_no']; $this->buildPayParams($isMobile); $this->signPayParams(); $payParamsTypeArr['signMsg'] = $this->signMsg; $payParamsTypeArr['gateway'] = $gateway; $payParamsTypeArr['entry_url'] = '/trade/kuaiqian'; return $payParamsTypeArr; } public function build_app($params) { return $this->build_url($params); } public function build_form($params) { return $this->build_url($params); } }
|