標籤:
//擷取使用者資訊
private function UlikeGetUserInfo($Wechat,$data)
{
$this->logger("到達UlikeFunction.inc.php中的UlikeGetUserInfo");
$access_token=$this->get_token();
$openid=$data[‘FromUserName‘];
$this->logger("FromUserName是:".$data[‘FromUserName‘]);
$url="https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
$this->logger("url是:".$url);
$jsonInformation=$this->http_curl($url);
$this->logger($jsonInformation);
$UserarrInformation=json_decode($jsonInformation,true);
$this->logger("UserarrInformation是:".$UserarrInformation);
$this->insertUserInformation($UserarrInformation,$Wechat);
}
//進行資料庫插值
private function insertUserInformation($User,$Wechat)
{
$this->logger("到達了資料庫進行插值處理!");
$this->logger($User[‘openid‘]);
$link=mysql_connect("127.0.0.1","root","");
if($link)
{
$this->logger("資料庫連接成功");
}else{
$this->logger("資料庫連接失敗");
}
mysql_select_db("weixin", $link);
$sql="insert into ulikeuser values(‘{$User["openid"]}‘,‘{$User["nickname"]}‘,‘{$User["sex"]}‘,‘{$User["city"]}‘,‘{$User["province"]}‘,‘{$User["headimgurl"]}‘,‘".time()."‘)";
// $sql="insert into Info values(‘lang‘,‘21‘,‘男生‘)";
//$sql2="select sex from Info where name=‘lilang1‘";
//mysql_query($sql,$link);
mysql_query("set names ‘utf8‘");//不加入會出現亂碼
$result=mysql_query($sql,$link);
if($result)
{$this->logger("您已經執行資料庫檔案!".$result);}
else
{
$this->logger("您的資料沒有插入成功!");
}
mysql_close($link);
}
php wampp 訪問資料庫