123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace refill\canbin_fs;
- require_once(BASE_HELPER_RAPI_PATH . '/canbin_fs/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,$regin_no,$other)
- {
- [$goods_id, $price] = parent::goods($quality,$amount,$card_type,$regin_no,$other);
- if($goods_id <= 0) return [0,0];
- $key = "{$card_type}-{$amount}-{$regin_no}";
- $price = config::Price[$key];
- if(empty($price)) {
- Log::record("channel cannot find price where name={$this->mName}, goods_id = {$goods_id} card_type={$card_type} amount={$amount} regin_no={$regin_no}",Log::ERR);
- return [0,0];
- } else {
- return [$goods_id,ncPriceFormat($price)];
- }
- }
- private function req_params(int $phone, int $amount, int $card_type, string $order_sn, string $regin_no)
- {
- $params['szAgentId'] = config::USER_ID;
- $params['szOrderId'] = $order_sn;
- $params['szPhoneNum'] = $phone;
- $params['nMoney'] = $amount;
- $params['nSortType'] = config::operator[$card_type];
- $params['szProductId'] = config::Product[$card_type][$regin_no][$amount];
- $params['nProductClass'] = 1;
- $params['nProductType'] = 1;
- $params['szTimeStamp'] = date("Y-m-d H:i:s");
- $params['szNotifyUrl'] = config::NOTIFY_URL;
- return $params;
- }
- public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
- {
- $order_sn = $params['order_sn'];
- $regin_no = $params['regin_no'] ?? -1;
- if($regin_no <= 0) {
- return [false, '省份获取错误', false];
- }
- $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $regin_no);
- $sign = $this->sign($params);
- $params['szVerifyString'] = $sign;
- $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
- if (empty($resp)) {
- return [false, '网络错误', true];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- $nRtn = $resp['nRtn'];
- if (empty($resp)) {
- return [false, '网络错误', true];
- } elseif ($nRtn === 0) {
- return [true, '', false];
- } elseif (in_array($nRtn, config::ERR_NOS, true)) {
- return [false, $resp['szRtnCode'], false];
- } elseif (in_array($nRtn, [2050, 999], true)) {
- $net_errno = "HTTP-{$nRtn}";
- return [false, $resp['szRtnCode'], true];
- } else {
- $err = 998;
- $net_errno = "HTTP-{$err}";
- return [false, $resp['szRtnCode'], true];
- }
- }
- }
- public function query($refill_info)
- {
- $params['szAgentId'] = config::USER_ID;
- $params['szOrderId'] = $refill_info['order_sn'];
- $key = config::KEY;
- $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}";
- $params['szVerifyString'] = md5($content);
- $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
- if (empty($resp)) {
- return [false, '网络错误', ''];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '网络错误', ''];
- }
- $official_sn = '';
- $status = $resp['nRtn'];
- if ($status === 5012) {
- $official_sn = $resp['szRtnMsg'];
- $updata['official_sn'] = $official_sn;
- Model('refill_order')->edit($refill_info['order_id'], $updata);
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($status === 5013) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif (in_array($status, [5011,5019],true)) {
- $order_state = ORDER_STATE_SEND;
- } elseif ($status === 5005 && (time() - $refill_info['commit_time'] > 300)) {
- $order_state = ORDER_STATE_NOEXIST;
- } else {
- return [false, $resp['szRtnMsg'], ''];
- }
- return [true, $order_state, $official_sn];
- }
- }
- public function balance()
- {
- $params['szAgentId'] = config::USER_ID;
- $key = config::KEY;
- $content = "szAgentId={$params['szAgentId']}&szKey={$key}";
- $params['szVerifyString'] = md5($content);
- $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
- if (empty($resp)) {
- return [false, '网络错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '网络错误'];
- } elseif ($resp['nRtn'] === 0) {
- return [true, $resp['fBalance']];
- } else {
- return [false, $resp['szRtnCode']];
- }
- }
- }
- private function sign($params)
- {
- $userid = config::USER_ID;
- $key = config::KEY;
- $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nMoney={$params['nMoney']}&nSortType={$params['nSortType']}";
- $content .= "&nProductClass={$params['nProductClass']}&nProductType={$params['nProductType']}&szTimeStamp={$params['szTimeStamp']}&szKey={$key}";
- return md5($content);
- }
- }
|