12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\models\system;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use think\facade\Env;
- /**
- * 物流公司
- * Class Express
- * @package app\models\system
- */
- class Site extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'site';
- use ModelTrait;
- public static function lst()
- {
- $model = new self;
- $model = $model->where('status', 1);
- return $model->select();
- }
- public static function addSite($name, $domain)
- {
- if (self::be(['domain' => $domain])) return self::setErrorInfo('已存在同名站点');
- return self::create([
- 'name' => $name,
- 'appid' => self::getNewAppId(),
- 'appsecret' => self::getNewSecret(),
- 'add_time' => time(),
- 'domain' => $domain,
- ]);
- }
- public static function getNewAppId()
- {
- do {
- $str = 'La' . strtoupper(substr(md5(time() . rand(0, 100000) . self::getLastInsID()), 0, 12));
- } while (self::be(['appid' => $str]));
- return $str;
- }
- public static function getNewSecret()
- {
- return strtoupper(md5(time() . rand(0, 100000) . self::getLastInsID()));
- }
- public static function checkSign($sign, $appid, $time, $action)
- {
- // var_dump(Env::get('app_debug'));
- if ($action != 'register' && $action != 'verify' && !Env::get('app_debug') && (strlen((string)$time) >= 13 ? $time / 1000 : $time) + 10 < time()) return self::setErrorInfo('签名已过期');
- return $sign === self::getSign($appid, $time) ? self::where('appid', $appid)->value('id') : self::setErrorInfo('无效的签名');
- }
- public static function getSign($appid, $time)
- {
- $appSecret = self::where('status', 1)->where('appid', $appid)->value('appsecret');
- if (!$appSecret) {
- return self::setErrorInfo('站点异常');
- }
- return strtoupper(md5(md5($appid . $appSecret . $time . $appid . $time . $appSecret . $appSecret . $appid)));
- }
- }
|