123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace refill\nanjingpushang_hf;
- require_once(BASE_HELPER_RAPI_PATH . '/nanjingpushang_hf/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 $card_no, int $amount, int $card_type, string $order_sn)
- {
- $params['merchantId'] = config::USER_ID;
- $params['amt'] = $amount;
- $params['phone'] = $card_no;
- $params['extOrderId'] = $order_sn;
- $params['notifyUrl'] = config::NOTIFY_URL;
- $params['operator'] = config::Cardtype2Name[$card_type];
- $sign = config::sign($params,['operator']);
- $params['md5'] = $sign;
- return $params;
- }
- public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
- {
- $order_sn = $params['order_sn'];
- $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
- $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);
- if (empty($resp)) {
- return [false, '网络错误', true];
- }
- $code = $resp['code'];
- if ($code === 0) {
- return [true, '', false];
- }
- elseif (in_array($code, config::ERR_NOS, true)) {
- return [false, $resp['msg'], false];
- }
- else {
- $err = 998;
- $net_errno = "HTTP-$err";
- return [false, $resp['msg'], true];
- }
- }
- }
- public function query($refill_info)
- {
- $params['merchantId'] = config::USER_ID;
- $params['extOrderId'] = $refill_info['order_sn'];
- $params['sign'] = config::sign($params);
- $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, '网络错误'];
- }
- $code = $resp['code'];
- $order = $resp['ext'];
- if ($code === 0)
- {
- $status = $resp['data'];
- if ($status === 4) {
- $updata['official_sn'] = $order['exchangeTraded'];
- Model('refill_order')->edit($refill_info['order_id'], $updata);
- return [true, ORDER_STATE_SUCCESS];
- } elseif ($status === 5) {
- return [true, ORDER_STATE_CANCEL];
- } elseif ($status === 3) {
- return [true, ORDER_STATE_SEND];
- }
- //9未查到订单(如果下单成功但是未查到订单不可以置为失败,需要进行核对)
- // elseif ($status === 9 && time() - $refill_info['commit_time'] > 600) {
- // return [true, ORDER_STATE_NOEXIST];
- // }
- else {
- return [false, $order['rechargeFailedReason']];
- }
- }
- else
- {
- return [false, $order['rechargeFailedReason'] ?? $resp['msg']];
- }
- }
- }
- public function balance()
- {
- $params['merchantId'] = config::USER_ID;
- $sign = config::sign($params);
- $params['sign'] = $sign;
- $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['code'] === 0) {
- $account = $resp['ext'];
- return [true, $account['balance']];
- } else {
- return [false, $resp['msg']];
- }
- }
- }
- }
|