SignUtil.php 965 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dingxiang-inc
  5. * Date: 2017/8/19
  6. * Time: 下午1:39
  7. */
  8. namespace common\thirdparty\dingxianginc\sdk\php\util;
  9. class SignUtil
  10. {
  11. private static $EVENT_CODE = "eventCode";
  12. private static $FLAG = "flag";
  13. public static function sign($appSecret, $ctuRequest)
  14. {
  15. $sortedParams = self::sortedParams($ctuRequest);
  16. return md5($appSecret . $sortedParams . $appSecret);
  17. }
  18. private static function sortedParams($ctuRequest)
  19. {
  20. $eventCode = $ctuRequest->eventCode;
  21. $flag = $ctuRequest->flag;
  22. $data = $ctuRequest->data;
  23. ksort($data);
  24. $paramStr = self::$EVENT_CODE . $eventCode . self::$FLAG . $flag;
  25. foreach ($data as $key => $value) {
  26. if (is_null($value)) {
  27. $paramStr .= $key . "null";
  28. } else {
  29. $paramStr .= $key . $value;
  30. }
  31. }
  32. return $paramStr;
  33. }
  34. }