123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace refill\rsanfang;
- require_once(BASE_HELPER_RAPI_PATH . '/rsanfang/config.php');
- use refill;
- use Log;
- use mtopcard;
- class RefillPhone extends refill\IRefillThird
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function getProductCode($goods_id, $sys_pcode)
- {
- $thrid_refill = Model('thrid_refill');
- $store_id = $this->mStoreID;
- $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $sys_pcode);
- if (empty($product)) {
- return false;
- } else {
- return $product['channel_code'];
- }
- }
- private function req_params(int $phone, int $amount, $card_type, string $order_sn, $channel_code): array
- {
- return [];
- }
- public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
- {
- $order_sn = $params['order_sn'];
- $goods_id = intval($params['goods_id']);
- $channel_code = $this->getProductCode($goods_id, $params['product_code']);
- if (empty($channel_code)) {
- return [false, '产品有误', false];
- }
- [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
- $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $channel_code);
- if (empty($params)) {
- return [false, '产品面值有误', false];
- }
- $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
- if (empty($resp))
- {
- return [false, '网络错误', true];
- }
- else
- {
- $resp = json_decode($resp, true);
- if (empty($resp))
- {
- return [false, '网络错误', true];
- }
- else
- {
- return [true, '', false];
- }
- }
- }
- public function query($refill_info): array
- {
- $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, '网络错误', ''];
- }
- else
- {
- return [true, ORDER_STATE_SUCCESS, ''];
- }
- }
- }
- public function balance(): array
- {
- $params = [];
- $resp = http_request(config::ORDER_URL, $params , 'POST');
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } else {
- return [true, 0];
- }
- }
- }
- }
|