123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace refill\kefei_fast;
- require_once(BASE_HELPER_RAPI_PATH . '/kefei_fast/config.php');
- use app\api\venderapi\card_checker\mtopcard;
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- //[$state, $errmsg, $neterr]
- public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
- {
- $typer = function ($card_type)
- {
- $types = [
- 4 => '移动',
- 5 => '联通',
- 6 => '电信'
- ];
- if(array_key_exists($card_type,$types)) {
- return $types[$card_type];
- } else {
- return false;
- }
- };
- $ispName = $typer($card_type);
- if(empty($ispName)) {
- return [false, '运营商错误', false];
- }
- $input = [
- "action" => "CZ",
- "orderId" => $params['order_sn'],
- "chargeAcct" => "$card_no",
- "chargeCash" => "$amount",
- "chargeType" => "0",
- 'ispName' => urlencode($ispName),
- "retUrl" => urlencode(config::NOTIFY_URL)
- ];
- $body = config::gen_body($input);
- if(empty($body)) {
- return [false, '提单参数不符合', false];
- }
- $resp = http_post_data(config::ORDER_URL, $body, config::ExtHeaders, $net_errno);
- if (empty($resp)) {
- return [false, '系统错误', true];
- }
- else
- {
- $resp = mb_convert_encoding($resp, "utf8", "gbk");
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', true];
- }
- $code = $resp['errorCode'];
- if ($code === 1) {
- return [true, $resp['chargeId'], false];
- } else {
- return [false, $resp['errorDesc'], false];
- }
- }
- }
- public function query($refill_info): array
- {
- $input = [
- "action" => "CX",
- "orderId" => $refill_info['order_sn'],
- ];
- $body = config::gen_body($input);
- $resp = http_post_data(config::ORDER_URL, $body, config::ExtHeaders, $net_errno);
- if (empty($resp)) {
- return [false, '系统错误', ''];
- }
- else
- {
- $resp = mb_convert_encoding($resp, "utf8", "gbk");
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', ''];
- }
- $errorCode = $resp['errorCode'];
- if ($errorCode === 1)
- {
- //0 等待处理 -
- //1 暂停处理 -
- //2 正在处理 -
- //6 正在缴费 -
- //11 处理成功 充值成功
- //16 缴费成功 充值成功
- //20 取消处理 充值失败
- //21 处理失败 充值失败
- //26 缴费失败 充值失败
- $status = intval($resp['orderStatuInt']);
- $official_sn = '';
- if (in_array($status, [11, 16])) {
- Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $resp['chargeId'], 'official_sn' => $official_sn]);
- $order_state = ORDER_STATE_SUCCESS;
- } elseif (in_array($status, [20, 21, 26])) {
- Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $resp['chargeId']]);
- $order_state = ORDER_STATE_CANCEL;
- } else {
- $order_state = ORDER_STATE_SEND;
- }
- return [true, $order_state, $official_sn];
- }
- elseif ($errorCode === -201 and (time() - $refill_info['commit_time']) >= 600) {
- return [true, ORDER_STATE_NOEXIST, ''];
- }
- else {
- return [false, $resp['errorDesc']];
- }
- }
- }
- public function balance(): array
- {
- $body = config::gen_body(["action" => "YE"]);
- $resp = http_post_data(config::ORDER_URL, $body, config::ExtHeaders, $net_errno);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- $resp = mb_convert_encoding($resp, "utf8", "gbk");
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } elseif ($resp['errorCode'] === 1) {
- return [true, ncPriceFormat($resp['agentBalance'])];
- } else {
- return [false, $resp['errorDesc']];
- }
- }
- }
- }
|