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

服务器配置

... ... @@ -35,6 +35,7 @@ class OpenServerController extends HomeBaseController
dump(cache('openid'));
dump(cache('ccc'));
dump(cache('admin_id'));
dump(cache('user_data'));
exit();
dump(cache('result'));
dump(cache('result1'));
... ... @@ -59,31 +60,40 @@ class OpenServerController extends HomeBaseController
//获取用户openid
$openid=$message->FromUserName;
cache('openid',$openid);
$admin_id=substr($message->EventKey,8);
cache('admin_id',$admin_id);
cache('ccc',$message->EventKey);
/*$third_party_user = Db::name('third_party_user')->where('openid',$openid)->find();
cache('third_party_user',$third_party_user);
if(!empty($third_party_user)){
$user = Db::name('user')->where('id',$third_party_user['user_id'])->find();
cache('user',$user);
if($user['channel'] == 2){
$result1 = Db::name('user')->where('id',$user['id'])->update(['admin_id'=>$admin_id,'channel'=>1]);
cache('result1',$result1);
}
}else{
//储存到推荐人推荐列表
$referrer = Db::name('referrer')->where(array('openid'=>$openid))->find();
cache('referrer',$referrer);
if(empty($referrer)){
$result = Db::name('referrer')->insert(array('admin_id'=>$admin_id,'openid'=>$openid,'create_time'=>time()));
cache('result',$result);
// return "推荐人关注!";
}else{
// return "已有推荐人!";
}
}*/
$param=substr($message->EventKey,8);
$data = explode("-",$param);
$my_user_id = $data[0];
$status = $data[1];
$third_party_user = Db::name('third_party_user')->where('openid',$openid)->find();
if(!$third_party_user){
//获取用户信息
$options=config('wechat_config');
$app = new Application($options);
$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));
}
// cache('third_party_user',$third_party_user);
// if(!empty($third_party_user)){
// $user = Db::name('user')->where('id',$third_party_user['user_id'])->find();
// cache('user',$user);
// if($user['channel'] == 2){
// $result1 = Db::name('user')->where('id',$user['id'])->update(['admin_id'=>$admin_id,'channel'=>1]);
// cache('result1',$result1);
// }
// }else{
// //储存到推荐人推荐列表
// $referrer = Db::name('referrer')->where(array('openid'=>$openid))->find();
// cache('referrer',$referrer);
// if(empty($referrer)){
// $result = Db::name('referrer')->insert(array('admin_id'=>$admin_id,'openid'=>$openid,'create_time'=>time()));
// cache('result',$result);
//// return "推荐人关注!";
// }else{
//// return "已有推荐人!";
// }
// }
}
break;
... ... @@ -126,4 +136,17 @@ class OpenServerController extends HomeBaseController
return false;
}
}
public function http_get($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
// grab URL, and print
if(curl_errno($ch)){
print curl_error($ch);
}
curl_close($ch);
return $result;
}
}
\ No newline at end of file
... ...