123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace refill\beixt;
- require_once(BASE_HELPER_RAPI_PATH . '/beixt/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function req_params(int $phone, int $amount ,string $order_sn)
- {
- $params['phone'] = $phone;
- $params['product_id'] = $amount;
- $params['tradeNo'] = $order_sn;
- $params['notify_url'] = config::NOTIFY_URL;
- return json_encode($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,$order_sn);
- $time = time();
- $api_user_name = config::API_USER_NAME;
- $sign = $this->sign($time);
- $header = [
- 'Content-Type: application/json',
- "API-USER-NAME: {$api_user_name}",
- "API-NAME: OrderCreate",
- "API-TIMESTAMP: {$time}",
- "API-SIGNATURE: {$sign}",
- ];
- $resp = http_post_data(config::REQUEST_URL,$params,$header,$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['ack'] == 'success') {
- return [true, $resp['message']['order_number'], false];
- } else {
- return [false, $resp['message'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params['order_number'] = $refill_info['ch_trade_no'];
- $params['tradeNo'] = $refill_info['order_sn'];
- $time = time();
- $api_user_name = config::API_USER_NAME;
- $sign = $this->sign($time);
- $header = [
- 'Content-Type: application/json',
- "API-USER-NAME: {$api_user_name}",
- "API-NAME: OrderQuery",
- "API-TIMESTAMP: {$time}",
- "API-SIGNATURE: {$sign}",
- ];
- $resp = http_post_data(config::REQUEST_URL,json_encode($params),$header);
- if (empty($resp)) {
- return [false,'系统错误'];
- }
- else
- {
- Log::record($resp,Log::DEBUG);
- $resp = json_decode($resp,true);
- if (empty($resp)) {
- return [false,'系统错误'];
- }
- elseif($resp['ack'] == 'success')
- {
- $data = $resp['order'];
- if ($data['shipping_status'] == 1) {
- $order_state = ORDER_STATE_SUCCESS;
- } elseif (in_array($data['shipping_status'], [0,3,4])) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif (in_array($data['shipping_status'], [2,5])) {
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $resp['message']];
- }
- return [true, $order_state];
- }
- else {
- return [false,$resp['message']];
- }
- }
- }
- public function balance()
- {
- return [false, '暂无余额接口'];
- }
- private function sign($time)
- {
- $ip = config::API_IP;
- $cert = config::API_CERT;
- $content = $ip.$time.$cert;
- return md5($content);
- }
- }
|