作者 王晓刚
1 个管道 的构建 通过 耗费 0 秒

服务器配置

... ... @@ -44,7 +44,8 @@ class OpenServerController extends HomeBaseController
}
public function responseMsg()
{
$app=new Application(config('wechat_config'));
$conf = config('wechat_config');
$app=new Application($conf);
$server = $app->server;
$server->setMessageHandler(function ($message) {
... ... @@ -72,7 +73,9 @@ class OpenServerController extends HomeBaseController
$accessToken = $app->access_token; // EasyWeChat\Core\AccessToken 实例
$token = $accessToken->getToken(false);
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$openid&lang=zh_CN";
cache('user_data',$this->http_get($url));
$user_data = json_decode($this->http_get($url),true);
$user_id = $this->new_user($user_data,$openid,$options['app_id']);
}
// cache('third_party_user',$third_party_user);
// if(!empty($third_party_user)){
... ... @@ -149,4 +152,35 @@ class OpenServerController extends HomeBaseController
curl_close($ch);
return $result;
}
public function new_user($wechat_user,$openid,$appId) {
$currentTime = time();
$ip = $this->request->ip(0, true);
$userId = Db::name("user")->insertGetId([
'create_time' => $currentTime,
'user_status' => 1,
'user_type' => 2,
'sex' => $wechat_user['original']['sex'],
'user_nickname' => $wechat_user['nickname'],
'avatar' => $wechat_user['avatar'],
'last_login_ip' => $ip,
'last_login_time' => $currentTime,
]);
$row=Db::name("third_party_user")->insert([
'openid' => $openid,
'user_id' => $userId,
'third_party' => 'public',
'nickname' => $wechat_user['nickname'],
'app_id' => $appId,
'last_login_ip' => $ip,
'union_id' => '',
'last_login_time' => $currentTime,
'create_time' => $currentTime,
'login_times' => 1,
'status' => 1,
'more' => json_encode($wechat_user)
]);
return $userId;
}
}
\ No newline at end of file
... ...