|
@@ -4,6 +4,7 @@ namespace refill\legou;
|
|
|
|
|
|
require_once(BASE_HELPER_RAPI_PATH . '/legou/config.php');
|
|
|
|
|
|
+use mtopcard\cards_helper;
|
|
|
use refill;
|
|
|
use Log;
|
|
|
|
|
@@ -14,17 +15,13 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
parent::__construct($cfgs);
|
|
|
}
|
|
|
|
|
|
- private function req_params(int $phone, int $amount, string $order_sn)
|
|
|
+ private function req_params(int $phone,$card_type, int $amount, string $order_sn)
|
|
|
{
|
|
|
$params['username'] = config::USERNAME;
|
|
|
$params['orderNumber'] = $order_sn;
|
|
|
$params['cardNumber'] = $phone;
|
|
|
$params['cardExt'] = $amount;
|
|
|
-
|
|
|
- $rechargeCard = $this->getrechargeCard($phone);
|
|
|
- $params['rechargeNum'] = $rechargeCard['rechargeNum'];
|
|
|
- $params['rechargePwd'] = $rechargeCard['rechargePwd'];
|
|
|
- $params['productNo'] = $rechargeCard['productNo'];
|
|
|
+ $params['productNo'] = config::ProductIDS[$card_type];
|
|
|
$params['timestamp'] = $this->getMillisecond();
|
|
|
$params['notifyUrl'] = config::NOTIFY_URL;
|
|
|
|
|
@@ -33,19 +30,39 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
|
|
|
public function add($card_no, $card_type, $amount, $params)
|
|
|
{
|
|
|
- $params = $this->req_params($card_no, $amount, $params['order_sn']);
|
|
|
+ $params = $this->req_params($card_no,$card_type, $amount, $params['order_sn']);
|
|
|
+
|
|
|
+ [$success,$card] = cards_helper::reserve($card_type,$amount,$params['buyer_id'],$card_no,$card_type,$params['order_id'],config::StoreIDS);
|
|
|
+ if(!$success) {
|
|
|
+ return [false, '没有可用卡密', false];
|
|
|
+ }
|
|
|
+
|
|
|
+ $rcard_no = $card->card_no();
|
|
|
+ $rcard_key = $card->card_key();
|
|
|
+ $params['rechargeNum'] = $rcard_no;
|
|
|
+ $params['rechargePwd'] = $rcard_key;
|
|
|
$sign = $this->sign($params);
|
|
|
$params['sign'] = $sign;
|
|
|
- $params['rechargeNum'] = $this->encryptWithOpenssl($params['rechargeNum']);
|
|
|
- $params['rechargePwd'] = $this->encryptWithOpenssl($params['rechargePwd']);
|
|
|
+
|
|
|
+ $params['rechargeNum'] = $this->encryptWithOpenssl($rcard_no);
|
|
|
+ $params['rechargePwd'] = $this->encryptWithOpenssl($rcard_key);
|
|
|
|
|
|
$resp = http_request(config::ORDER_URL, $params , 'POST' , false , config::ExtHeaders);
|
|
|
if ($resp === false) {
|
|
|
- return [false, '系统错误', true];
|
|
|
- } else {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
Log::record($resp, Log::DEBUG);
|
|
|
$resp = json_decode($resp ,true);
|
|
|
- if($resp['code']['status'] == 100000) {
|
|
|
+
|
|
|
+ if($resp == false) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = intval($resp['code']['status']);
|
|
|
+
|
|
|
+ if($status == 100000) {
|
|
|
return [true, $resp['obj'], false];
|
|
|
}
|
|
|
return [false , $resp['code']['desc'], false];
|
|
@@ -104,17 +121,7 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
private function encryptWithOpenssl($data = '')
|
|
|
{
|
|
|
$key = substr(config::KEY , 0 ,16);
|
|
|
- $iv = substr(config::KEY , -16);;
|
|
|
+ $iv = substr(config::KEY , -16);
|
|
|
return base64_encode(openssl_encrypt($data, "AES-128-CBC", $key, OPENSSL_RAW_DATA, $iv));
|
|
|
}
|
|
|
-
|
|
|
- private function getrechargeCard($phone)
|
|
|
- {
|
|
|
- //判断手机号运营商,获取卡号卡密,产品编号
|
|
|
- $rechargeNum = 1;
|
|
|
- $rechargePwd = 2;
|
|
|
- $productNo = 3;
|
|
|
- return ['rechargeNum' => $rechargeNum , 'rechargePwd' => $rechargePwd , 'productNo' => $productNo];
|
|
|
-
|
|
|
- }
|
|
|
}
|