BaseController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Http\Controllers\WapBrowser;
  3. use Illuminate\Routing\Controller;
  4. use Illuminate\Http\Request;
  5. class BaseController extends Controller
  6. {
  7. /**
  8. * 公众号接口签名密钥
  9. * @var string
  10. */
  11. protected $secret_key = 'zhuishuyun#_2017';
  12. /**
  13. * 渠道id
  14. * @var
  15. */
  16. protected $distribution_channel_id;
  17. function __construct(Request $request)
  18. {
  19. $domain = _domain();
  20. $this->distribution_channel_id = str_replace('bsite','',explode('.',$domain)[0]);
  21. if(!is_numeric($this->distribution_channel_id)){
  22. $this->distribution_channel_id = decodeDistributionChannelId($this->distribution_channel_id);
  23. }
  24. }
  25. /**
  26. * 公众号签名@华灯初上
  27. * @param $params
  28. * @return string
  29. */
  30. protected function getSign($params)
  31. {
  32. $url = $this->arr_to_url($params, false);
  33. $url = $url . '&key=' . $this->secret_key;
  34. $sign = md5($url);
  35. return $sign;
  36. }
  37. /**
  38. * 公众号签名@华灯初上
  39. * @param $array
  40. * @param bool $has_sign
  41. * @return string
  42. */
  43. protected function arr_to_url($array, $has_sign = false)
  44. {
  45. ksort($array);
  46. reset($array);
  47. $arg = "";
  48. while (list ($name, $val) = each($array)) {
  49. if ($name == 'sign' && !$has_sign) continue;
  50. if (strpos($name, "_") === 0)
  51. continue;
  52. if (is_array($val))
  53. $val = join(',', $val);
  54. if ($val === "")
  55. continue;
  56. $arg .= $name . "=" . $val . "&";
  57. }
  58. $arg = substr($arg, 0, count($arg) - 2);
  59. return $arg;
  60. }
  61. }