|
@@ -0,0 +1,217 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\suning;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/suning/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function goods($quality,int $amount,int $card_type,$other)
|
|
|
+ {
|
|
|
+ [$goods_id, $price] = parent::goods($quality,$amount,$card_type,$other);
|
|
|
+ if($goods_id <= 0) return [0,0];
|
|
|
+
|
|
|
+ $store_id = $this->mStoreID;
|
|
|
+ $pcode = $other['product_code'];
|
|
|
+ $thrid_refill = Model('thrid_refill');
|
|
|
+ $product = $thrid_refill->getProviderProduct($store_id,$goods_id,$pcode);
|
|
|
+ if(empty($product)) {
|
|
|
+ Log::record("cannot find provider's produce where name={$this->mName}, goods_id = {$goods_id} pcode={$pcode}",Log::ERR);
|
|
|
+ return [0,0];
|
|
|
+ } else {
|
|
|
+ return [$goods_id,ncPriceFormat($product['channel_amount'])];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(string $order_sn, string $product_code,$quantity)
|
|
|
+ {
|
|
|
+ $params['partner'] = config::PARTNER;
|
|
|
+ $params['service'] = 'cardSaleAgent';
|
|
|
+ $params['format'] = 'json';
|
|
|
+ $params['orderTime'] = time();
|
|
|
+ $params['ProductCode'] = $product_code;
|
|
|
+ $params['BuyCount'] = $quantity;
|
|
|
+ $params['MOrderID'] = $order_sn;
|
|
|
+ $params['CustomerIP'] = config::API_IP;
|
|
|
+ $params['IsCallback'] = 1;
|
|
|
+ $params['CallBackUrl'] = config::NOTIFY_URL;
|
|
|
+ $params['Version'] = '1.0';
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getProductCode($goods_id,$sys_pcode)
|
|
|
+ {
|
|
|
+ $thrid_refill = Model('thrid_refill');
|
|
|
+ $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
|
|
|
+ if (empty($product)) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return $product['channel_code'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //直充提单
|
|
|
+ public function add($card_no, $card_type, $amount, $params)
|
|
|
+ {
|
|
|
+ if(empty($card_no)) {
|
|
|
+ return $this->cardkey_add($params);
|
|
|
+ } else {
|
|
|
+ return $this->direct_add($card_no, $params);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function direct_add($card_no, $params)
|
|
|
+ {
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ $goods_id = intval($params['goods_id']);
|
|
|
+ $product_code = $this->getProductCode($goods_id,$params['product_code']);
|
|
|
+
|
|
|
+ Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
|
|
|
+ $quantity = intval($params['quantity']);
|
|
|
+
|
|
|
+ $params = $this->req_params($order_sn,$product_code,$quantity);
|
|
|
+
|
|
|
+ $params['ChargeAccount'] = $card_no;
|
|
|
+ $params['ChargeAccountType'] = 1;//账号类型1 手机号,2 QQ号,3 微信号
|
|
|
+
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['Sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_URL, $params);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ } elseif ($resp['Code'] == 999) {
|
|
|
+ return [true, $resp['OrderModel']['OrderId'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['Msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function cardkey_add($params)
|
|
|
+ {
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ $goods_id = intval($params['goods_id']);
|
|
|
+ $product_code = $this->getProductCode($goods_id,$params['product_code']);
|
|
|
+ Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
|
|
|
+
|
|
|
+ $quantity = intval($params['quantity']);
|
|
|
+ $params = $this->req_params($order_sn,$product_code,$quantity);
|
|
|
+
|
|
|
+ $params['PublicKey'] = config::PUBLIC_KEY;
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['Sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::CARD_ORDER_URL, $params);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ } elseif ($resp['Code'] == 999) {
|
|
|
+ return [true, $resp['OrderModel']['OrderId'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['Msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['AppKey'] = config::APP_KEY;
|
|
|
+ $params['TimesTamp'] = time();
|
|
|
+ $params['MOrderID'] = $refill_info['order_sn'];
|
|
|
+ $params['Version'] = '1.0';
|
|
|
+
|
|
|
+ $content = config::APP_KEY . $params['TimesTamp'] . $params['Version'] . $params['MOrderID'] . config::App_Secret;
|
|
|
+ $params['Sign'] = strtoupper(md5($content));
|
|
|
+
|
|
|
+ $resp = http_request(config::QUERY_URL, $params);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ elseif ($resp['Code'] == 999)
|
|
|
+ {
|
|
|
+ $status = intval($resp['Data']['OrderState']);
|
|
|
+ if ($status === 2)
|
|
|
+ {
|
|
|
+ if(!empty($resp['Data']['CardData'])) {
|
|
|
+ $result = $this->rsa_decode($resp['Data']['CardData']);
|
|
|
+ if (empty($result)) {
|
|
|
+ $data['ret_state'] = 2;
|
|
|
+ $data['card_info'] = '查询接口,解密失败';
|
|
|
+ } else {
|
|
|
+ $data['ret_state'] = 1;
|
|
|
+ $data['card_info'] = $result;
|
|
|
+ }
|
|
|
+ Model('thrid_refill')->edit_third($refill_info['order_id'], $data);
|
|
|
+ }
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ }
|
|
|
+ elseif ($status === 3) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ }
|
|
|
+ elseif (in_array($status, [1,4])) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [false, $resp['Message']];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [false, $resp['Message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function rsa_decode($encrypted)
|
|
|
+ {
|
|
|
+ $ret = openssl_private_decrypt(base64_decode($encrypted), $decrypted, config::PRIVATE_KEY);
|
|
|
+ if ($ret) {
|
|
|
+ $result = json_decode($decrypted, true);
|
|
|
+ return $result;
|
|
|
+ } else {
|
|
|
+ $err = openssl_error_string();
|
|
|
+ Log::record("sctongqian callback openssl_private_decrypt error={$err}", Log::ERR);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $content = config::APP_KEY . $params['BuyCount'] . $params['CallBackUrl'] . $params['ChargeAccount'] . $params['CustomerIP'] . $params['MOrderID'];
|
|
|
+ $content .= $params['ProductCode'] . $params['TimesTamp'] . $params['Version'] . config::App_Secret;
|
|
|
+ return strtoupper(md5($content));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|