public static function saveWeChatUser($user) { $oldUser = self::getWeChatUserByOpenId($user->openId); if (isset($oldUser)) { $oldUser->unionId = $user->unionId; $oldUser->nickname = $user->nickname; $oldUser->sex = $user->sex; $oldUser->city = $user->city; $oldUser->province = $user->province; $oldUser->country = $user->country; $oldUser->subscribeTime = $user->subscribeTime; $oldUser->subscribe = $user->subscribe; $oldUser->headImgUrl = $user->headImgUrl; $oldUser->openId = $user->openId; $oldUser->save(); $mcdKey = 'm:weChatUserService?openId=' . $user->openId; Wk::redis()->delete($mcdKey); return true; } else { $oldUser = new TAR_WechatUser(); $oldUser->unionId = $user->unionId; $oldUser->nickname = $user->nickname; $oldUser->sex = $user->sex; $oldUser->city = $user->city; $oldUser->province = $user->province; $oldUser->country = $user->country; $oldUser->subscribeTime = $user->subscribeTime; $oldUser->subscribe = $user->subscribe; $oldUser->headImgUrl = $user->headImgUrl; $oldUser->openId = $user->openId; $oldUser->save(); return true; } return false; }
public function getBaseAccessToken($forceMc = false) { // access_token有访问限制(1天2000次),接口过期时间7200秒,因此设置缓存 $access_token = Wk::redis()->get(self::WX_ACCESS_TOKEN_MC_KEY); Wk::logger()->log("access_token in Mcd: " . $access_token); if ($access_token == false || $forceMc == true) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->wx_akey . '&secret=' . $this->wx_skey; curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); if ($data === false) { throw new Wk_Exception('', TErrorConstants::E_SNS_LOGIN); } $data = json_decode($data); if (!empty($data->errcode)) { throw new Wk_Exception('', TErrorConstants::E_SNS_LOGIN); } if (empty($data->access_token)) { throw new Wk_Exception('', TErrorConstants::E_SNS_LOGIN); } $access_token = $data->access_token; Wk::logger()->log("access_token in request: " . $access_token); Wk::redis()->set(self::WX_ACCESS_TOKEN_MC_KEY, $access_token, 3600); } return $access_token; }
public function destroy($id) { $redKey = 'wk:session:' . $id; $n = Wk::redis()->del($redKey); if ($n == 1) { return true; } return false; }
public static function sendCode($mobile, $userid = 0) { $key = self::CACHEKEY . $mobile; $value = Wk::redis()->get($key); if ($value !== false) { throw new Wk_Exception("", TErrorConstants::E_SMS_CODE_TOO_FREQUENCY); } if (WAKA_ENV == "production") { $randstr = mt_rand(10000, 99999); } else { $randstr = "12345"; } // to do 发短信 Wk::redis()->set($key, $randstr, 60); $mobileVerify = new TAR_MobileVerify(); $mobileVerify->mobile = $mobile; $mobileVerify->userid = 0; $mobileVerify->randstr = $randstr; $mobileVerify->state = 0; $mobileVerify->expire = date("Y-m-d H:i:s", time() + 5 * 60); $mobileVerify->save(); }
/** * @return Wk_City_List */ public function getWkCityList() { $cityListRKey = "wk:city:getCityList"; $res = unserialize(Wk::redis()->get($cityListRKey)); if (!$res) { $cities = TAR_City::findAll("where status in (0, 1) order by status asc"); $res = new Wk_City_List(); $res->list = []; foreach ($cities as $city) { $item = new Wk_City(); $item->id = $city->id; $item->name = $city->name; $item->province = $city->province; $item->status = $city->status; $item->lat = $city->lat; $item->lng = $city->lng; $res->list[] = $item; } Wk::redis()->set($cityListRKey, serialize($res), 20 * 60); } return $res; }