DuoMaiLianMengUtil.php 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Http\Utils\DuoMaiLianMeng;
  3. use App\Http\Utils\BaseUtil;
  4. /**
  5. * 多麦工具栏类(https://open.duomai.com/)
  6. * Class DuoMaiLianMengUtil
  7. * @package App\Http\Utils\DuoMaiLianMeng
  8. */
  9. class DuoMaiLianMengUtil extends BaseUtil
  10. {
  11. /**
  12. * 获取签名
  13. * @param $params 请求参数
  14. * @param $serviceName 服务名称
  15. */
  16. public static function getSign($params,$serviceName)
  17. {
  18. $systemParams = [
  19. "app_key"=>env("DUO_MAI_APP_KEY"),
  20. "timestamp"=>time(),
  21. "service"=>$serviceName
  22. ];
  23. $params = array_merge($params,$systemParams);
  24. ksort($params);
  25. $sign = "";
  26. foreach ($params as $key=>$val){
  27. $sign .= $key.$val;
  28. }
  29. $sign .= json_encode($params);
  30. $sign = env("DUO_MAI_APP_SECRET").$sign.env("DUO_MAI_APP_SECRET");
  31. $sign = strtoupper(md5($sign));
  32. $systemParams["sign"] = $sign;
  33. return http_build_query($systemParams);
  34. }
  35. }