config.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace refill\gdsinopec;
  3. use Log;
  4. class config
  5. {
  6. const TOKEN_URL = 'http://open.huizhichun.com/open/api/token'; //获取AccessToken
  7. const SUPPLIER_URL = 'http://open.huizhichun.com/open/api/coupon/findSupplierList'; //获取电子券来源
  8. const LIST_URL = 'http://open.huizhichun.com/open/api/coupon/findList'; //获取电子券列表
  9. const ORDER_URL = 'http://open.huizhichun.com/open/api/coupon/purchase?access_token='; //采购电子券
  10. const QUERY_URL = 'http://open.huizhichun.com/open/api/coupon/orderStatus'; //订单查询
  11. const APP_ID = 'KA2702579';
  12. const APP_SECRET = '5af4a0fe9e4c4763b7ab54123778d0ca';
  13. const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_sinopec.php";
  14. const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
  15. const PAGE_SIZE = 200;
  16. //省份映射 我方省份 => 上游省份编号
  17. const SUPPLIER_ORIGIN = [
  18. 19 => 100, //广东
  19. 20 => 101, //广西
  20. ];
  21. public function get_access_token()
  22. {
  23. $params['appid'] = config::APP_ID;
  24. $params['secret'] = config::APP_SECRET;
  25. $resp = http_request(config::TOKEN_URL, $params, 'GET', false, config::ExtHeaders, $net_errno);
  26. if (empty($resp)) {
  27. return [false, '网络错误'];
  28. }
  29. else
  30. {
  31. Log::record($resp, Log::DEBUG);
  32. $resp = json_decode($resp, true);
  33. if (empty($resp)) {
  34. return [false, '网络错误'];
  35. } elseif ($resp['state'] === 'ok') {
  36. $result = $resp['data'];
  37. $access_token = $result['access_token'];
  38. $expires_in = intval($result['expires_in']);
  39. wcache('vendor-cfgs', ['gdsinopec-token' => $access_token,'gdsinopec-time' => time() + $expires_in],'refill-');
  40. return [true, $expires_in];
  41. } else {
  42. return [false, $resp['info']];
  43. }
  44. }
  45. }
  46. public static function token()
  47. {
  48. $result = rcache('vendor-cfgs','refill-','gdsinopec-token,gdsinopec-time');
  49. if(empty($result)) {
  50. return false;
  51. }
  52. $expired_time = $result['gdsinopec-time'];
  53. $token = $result['gdsinopec-token'];
  54. if ($expired_time > time()) {
  55. return $token;
  56. } else {
  57. return false;
  58. }
  59. }
  60. }