123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace refill\yuke;
- require_once(BASE_HELPER_RAPI_PATH . '/yuke/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 $card_type, int $amount, string $order_sn)
- {
- $params['rechargeAccount'] = $phone;
- $params['rechargeAmount'] = $amount;
- $params['tPfChannelId'] = config::CHANNEL_ID;
- $params['orderType'] = 0;
- $params['outOrderId'] = $order_sn;
- $params['randomNumber'] = $this->createNoncestr(10);
- return $params;
- }
- public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
- {
- $params = $this->req_params($card_no, $card_type, $amount, $params['order_sn']);
- $sign = $this->sign($params);
- $params['sign'] = $sign;
- $params = json_encode($params);
- $resp = http_post_data(config::ORDER_URL, $params , 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];
- } elseif ($resp['code'] === 1) {
- return [true, $resp['data']['order_sn'], false];
- } else {
- return [false, $resp['message'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params['tPfChannelId'] = config::CHANNEL_ID;
- $params['outOrderId'] = $refill_info['order_sn'];
- $params = json_encode($params);
- $resp = http_post_data(config::QUERY_URL, $params , 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'] === 1)
- {
- $status = $resp['data']['orderInfo']['orderStatus'];
- if ($status === 2) {
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($status === 3 || $status === 4) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif ($status === 1) {
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $status];
- }
- return [true, $order_state];
- }
- elseif ($resp['code'] === -2004 && (time() - $refill_info['commit_time'] > 600))
- {
- return [true, ORDER_STATE_NOEXIST];
- }
- else
- {
- return [false, $resp['message']];
- }
- }
- }
- public function balance()
- {
- $params['tPfChannelId'] = config::CHANNEL_ID;
- $params['tunnelType'] = 0;
- $key = config::SECRET_KEY;
- $content = "tPfChannelId={$params['tPfChannelId']}&tunnelType={$params['tunnelType']}&secret_key={$key}";
- $params['sign'] = strtoupper(md5($content));
- $params = json_encode($params);
- $resp = http_post_data(config::BALANCE_URL, $params , 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'] == 1) {
- return [true, $resp['data']['amountOfMoney']];
- } else {
- return [false, $resp['message']];
- }
- }
- }
- private function createNoncestr( $length = 32 )
- {
- $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
- $str ="";
- for ( $i = 0; $i < $length; $i++ ) {
- $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
- }
- return $str;
- }
- private function sign($params)
- {
- $key = config::SECRET_KEY;
- $content = "orderType={$params['orderType']}&tPfChannelId={$params['tPfChannelId']}&rechargeAccount={$params['rechargeAccount']}&rechargeAmount={$params['rechargeAmount']}";
- $content .= "&randomNumber={$params['randomNumber']}&secret_key={$key}";
- return strtoupper(md5($content));
- }
- }
|