123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace refill\yushang_normal;
- require_once(BASE_HELPER_RAPI_PATH . '/yushang_normal/config.php');
- use mtopcard;
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
- {
- $oper_getter = function ($card_type)
- {
- if($card_type == mtopcard\ChinaMobileCard) {
- return 'YD';
- }
- elseif($card_type == mtopcard\ChinaUnicomCard) {
- return 'LT';
- }
- elseif($card_type == mtopcard\ChinaTelecomCard) {
- return 'DX';
- }
- else {
- return false;
- }
- };
- $operator = $oper_getter($card_type);
- $sku_code = config::sku_code($card_type,$amount);
- if($operator === false || empty($sku_code)) {
- return [];
- }
- $input = [
- 'BuyCount' => 1,
- 'CallBackUrl' => config::NOTIFY_URL,
- 'ChargeAccount' => $phone,
- 'CustomerIP' => '127.0.0.1',
- 'MOrderID' => $order_sn,
- 'ProductCode' => $sku_code,
- 'TimesTamp' => config::time_stamp()
- ];
- return config::gen_params($input,config::add_keys);
- }
- //[$state, $errmsg, $neterr]
- public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
- {
- $params = $this->add_params($card_no, $amount, $params['order_sn'],$card_type);
- if(empty($params)) {
- return [false, '提单参数不符合', false];
- }
- $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $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];
- } elseif ($resp['Code'] === 999) { /// 999 收单成功
- return [true, $resp['OrderID'], false];
- } else {
- return [false, $resp['Msg'], false];
- }
- }
- }
- public function query($refill_info): array
- {
- $input = [
- 'TimesTamp' => config::time_stamp(),
- 'MOrderID' =>$refill_info['order_sn']
- ];
- $params = config::gen_params($input,config::query_keys);
- $resp = http_request(config::QUERY_URL, $params , 'POST');
- if (empty($resp)) {
- return [false, '系统错误', ''];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', ''];
- }
- $code = intval($resp['Code']);
- if ($code === 999)
- {
- $val = $resp['Data'];
- $status = intval($val['OrderState']);
- $official_sn = $val['ExtendParam']['OfficialOrderID'] ?? '';
- //充值状态:1=订单正在处理中,2=订单成功,3=订单失败,4=订单状态异常或位置
- if ($status == 2) {
- Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['OrderID'],'official_sn' => $official_sn]);
- $order_state = ORDER_STATE_SUCCESS;
- }
- elseif ($status == 3) {
- Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['OrderID']]);
- $order_state = ORDER_STATE_CANCEL;
- }
- else {
- $order_state = ORDER_STATE_SEND;
- }
- return [true, $order_state, $official_sn];
- }
- elseif($code === 10 and (time() - $refill_info['commit_time']) >= 300) {
- return [true, ORDER_STATE_NOEXIST, ''];
- }
- else
- {
- return [false, $resp['Msg']];
- }
- }
- }
- public function balance(): array
- {
- $input = [
- 'TimesTamp' => config::time_stamp()
- ];
- $params = config::gen_params($input,config::balance_keys);
- $resp = http_request(config::BALANCE_URL, $params , 'POST');
- 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) {
- return [true, ncPriceFormat($resp['Data'][0]['Balance'])];
- } else {
- return [false, $resp['Msg']];
- }
- }
- }
- }
|