cls_common.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * Krpano100 ucenter常用方法类
  4. * ============================================================================
  5. * 技术支持:2015-2099 成都世纪川翔科技有限公司
  6. * 官网地址: http://www.krpano100.com
  7. * ----------------------------------------------------------------------------
  8. * $Author: liyuanzhang 932625974#qq.com $
  9. * $Id: config_ucenter_default.php 28028 2016-02-19Z liyuanzhang $
  10. */
  11. if(!defined('IN_T'))
  12. {
  13. die('hacking attempt');
  14. }
  15. class UCommon{
  16. private $appid;
  17. private $appsecret;
  18. //构造方法
  19. //@param $appid:接口id $appsecret:接口密钥
  20. function __construct($appid,$appsecret){
  21. $this->Db = $GLOBALS['Db'];
  22. $this->Base = $GLOBALS['Base'];
  23. $this->appid = $appid;
  24. $this->appsecret = $appsecret;
  25. }
  26. //验证signature
  27. public function checkSignature()
  28. {
  29. $signature = $_GET["signature"];//客户端加密的KEY
  30. $timestamp = $_GET["timestamp"];//客户端的时间戳,10位整数
  31. $nonce = $_GET["nonce"];//客户端生成的随机数
  32. $tmpArr = array($this->appid, $this->appsecret, $timestamp, $nonce); //构建一个数组
  33. //use SORT_STRING rule
  34. sort($tmpArr, SORT_STRING); //将数组每一项作为字符串,进行升序排序
  35. $tmpStr = implode($tmpArr); //将数组连接为字符串
  36. $tmpStr = sha1($tmpStr); //对字符串进行sha1加密
  37. //签名合法
  38. if($tmpStr == $signature){
  39. return true;
  40. }else{
  41. echo ERROR_CHECK_FAILURE;
  42. exit;
  43. }
  44. }
  45. }
  46. ?>