设为首页 加入收藏

TOP

微信公众平台开发(二)
2017-10-10 08:34:26 】 浏览:10082
Tags:公众 平台 开发
where(array("openid"=>$openid))->one();
if($customer == null){
$customerinfo_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN ';
$customerinfo_json = $this->curl_get($customerinfo_url);
$customerinfo = json_decode($customerinfo_json, true);

$customer = new Customer();
$customer->name = $customerinfo['nickname'];
$customer->headimg = $customerinfo['headimgurl'];
$customer->sex = $customerinfo['sex'];
$customer->openid = $customerinfo['openid'];
$customer->address = $customerinfo['country'].$customerinfo['province'].$customerinfo['city'];
$customer->created_at = time();
$customer->updated_at = time();
$customer->is_del = 0;
$customer->money = 0;
$customer->save();
}

setCookie("is_login", 1, time()+3600*24*30*12, "/");
setCookie("customer_id", $customer->id, time()+3600*24*30*12, "/");

$redirect_url = $hostname;
Header("Location: $redirect_url");
}

 

public function curl_get($url)
{
$host = parse_url($url, PHP_URL_HOST);
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)');
curl_setopt($ch,CURLOPT_REFERER, $host);
curl_setopt($ch,CURLOPT_TIMEOUT, 15);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$str = curl_exec($ch);
curl_close($ch);
return $str;
}

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇php解决约瑟夫环 下一篇前端到后台ThinkPHP开发整站(完)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目