config.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace refill\shantong;
  3. class config
  4. {
  5. const ORDER_URL = 'http://wf-recharge-api.shantongdata.com/api/v1/mobile/order/apply';
  6. const QUERY_URL = 'http://wf-recharge-api.shantongdata.com/api/v1/mobile/order/query';
  7. const BALANCE_URL = 'http://wf-recharge-api.shantongdata.com/api/v1/agent/balance/enquiry';
  8. const AGENT_ID = '1004';
  9. const transactionPin = 'Qwer@1234';
  10. const APP_ID = 'cz_1004';
  11. const APP_KEY = '3c7795c7-beb3-45fc-b764-98c270062c90';
  12. const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_shantong.php";
  13. const ExtHeaders = ['Content-Type: application/json;charset=UTF-8'];
  14. private static function createNoncestr( $length = 32 )
  15. {
  16. $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  17. $str ="";
  18. for ( $i = 0; $i < $length; $i++ ) {
  19. $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
  20. }
  21. return $str;
  22. }
  23. public static function pub_params()
  24. {
  25. $params['appId'] = config::APP_ID;
  26. $params['nonceStr'] = self::createNoncestr();
  27. $params['timeStamp'] = time();
  28. return $params;
  29. }
  30. public static function sign($params)
  31. {
  32. ksort($params);
  33. $content = '';
  34. foreach ($params as $key => $value) {
  35. if(self::check_empty($value) === false) {
  36. $content .= "{$key}={$value}&";
  37. }
  38. }
  39. $content .= 'appKey='.config::APP_KEY;
  40. return md5($content);
  41. }
  42. public static function check_empty($value)
  43. {
  44. if (!isset($value))
  45. return true;
  46. if ($value === null)
  47. return true;
  48. if (trim($value) === "")
  49. return true;
  50. return false;
  51. }
  52. }