1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace refill\gdsinopec;
- use Log;
- class config
- {
- const TOKEN_URL = 'http://open.huizhichun.com/open/api/token'; //获取AccessToken
- const SUPPLIER_URL = 'http://open.huizhichun.com/open/api/coupon/findSupplierList'; //获取电子券来源
- const LIST_URL = 'http://open.huizhichun.com/open/api/coupon/findList'; //获取电子券列表
- const ORDER_URL = 'http://open.huizhichun.com/open/api/coupon/purchase?access_token='; //采购电子券
- const QUERY_URL = 'http://open.huizhichun.com/open/api/coupon/orderStatus'; //订单查询
- const APP_ID = 'KA2702579';
- const APP_SECRET = '5af4a0fe9e4c4763b7ab54123778d0ca';
- const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_sinopec.php";
- const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
- const PAGE_SIZE = 200;
- //省份映射 我方省份 => 上游省份编号
- const SUPPLIER_ORIGIN = [
- 19 => 100, //广东
- 20 => 101, //广西
- ];
- public function get_access_token()
- {
- $params['appid'] = config::APP_ID;
- $params['secret'] = config::APP_SECRET;
- $resp = http_request(config::TOKEN_URL, $params, 'GET', false, config::ExtHeaders, $net_errno);
- if (empty($resp)) {
- return [false, '网络错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '网络错误'];
- } elseif ($resp['state'] === 'ok') {
- $result = $resp['data'];
- $access_token = $result['access_token'];
- $expires_in = intval($result['expires_in']);
- wcache('vendor-cfgs', ['gdsinopec-token' => $access_token,'gdsinopec-time' => time() + $expires_in],'refill-');
- return [true, $expires_in];
- } else {
- return [false, $resp['info']];
- }
- }
- }
- public static function token()
- {
- $result = rcache('vendor-cfgs','refill-','gdsinopec-token,gdsinopec-time');
- if(empty($result)) {
- return false;
- }
- $expired_time = $result['gdsinopec-time'];
- $token = $result['gdsinopec-token'];
- if ($expired_time > time()) {
- return $token;
- } else {
- return false;
- }
- }
- }
|