标签:
<?php
define("TOKEN","wang");
define(‘APPID‘, "wx82a6532dc6b6c750");
define("APPSERCRET", "5ba7ef1fa9f9712532565ca2a047744b");
$weixin = new Weixin();
//$res_create_menu = $weixin->create_menu();
//var_dump($res_create_menu);
//$res_get_menu = $weixin->get_menu();
//var_dump($res_get_menu);
$access_token = $weixin->getAccessToken();
/*$res_create_menu = $weixin->create_menu();
var_dump($res_get_menu);*/
//$user_info = $weixin->get_user_info();
echo $access = $weixin->getAccessToken();
if(isset($_GET[‘echostr‘]))
{
$weixin->valid();
}else
{
$weixin->responseMsg();
}
function curlOpen($url, $cfg)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
if($cfg[‘ssl‘])
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
class Weixin
{
public function getAccessToken()
{
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
$time = time();
$sql = "select * from pre_access_token limit 1";
$result = $db->query($sql);
$res = $db->fetch_array($result);
if(empty($res)){
//如果是空的话证明是第一次获取access_token
$res_getAccessToken = $this->getAccessToken_new(APPID,APPSERCRET);
//得到access_token
if(!empty($res_getAccessToken[‘access_token‘])){
//如果创建菜单成功,执行插入操作
$access_token_arr = $this->getAccessToken_new(APPID,APPSERCRET);
$access_token = $access_token_arr[‘access_token‘];
$expires_in = $access_token_arr[‘expires_in‘];
$create_time = time();
$create_date = date("Y-m-d H:i:s",$create_time);
$sql_insert = "insert into pre_access_token(access_token,expires_in,create_time,create_date)
values(‘{$access_token}‘,{$expires_in},{$create_time},‘{$create_date}‘)";
$result_insert = $db->query($sql_insert);
if($db->getLastId()>0){
return $access_token;
}else{
return false;
}
}
}else{
//如果非空的话,查询出里面的时间,和当前时间对比,如果大于了过期的时间,就从新获取,并更新数据库,否则的话就用这个
$time_now = time();
if($time_now - $res[‘create_time‘] > $res[‘expires_in‘]){
//超过了过期时间 从新获取access_token 并更新
$access_token_arr = $this->getAccessToken_new(APPID,APPSERCRET);
$access_token = $access_token_arr[‘access_token‘];
$expires_in = $access_token_arr[‘expires_in‘];
$create_time = time();
$create_date = date("Y-m-d H:i:s",$create_time);
$sql_update = "update pre_access_token set access_token = ‘{$access_token}‘,expires_in = ‘{$expires_in}‘,create_time={$create_time},create_date=‘{$create_date}‘ where id={$res[‘id‘]}";
$result_update = $db->query($sql_update);
if($db->getAffectedRows()>0){
return $access_token;
}else{
return false;
}
}else{
//就用这个access_token
return $res[‘access_token‘];
}
}
}
public function getAccessToken_new($AppId, $AppSecret)
{
$cfg[‘ssl‘] = true;
$result = curlOpen("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$AppId&secret=$AppSecret", $cfg);
return json_decode($result,true);
}
function https_request($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
public function create_menu()
{
/*$jsonmenu = ‘ {
"button":[
{
"type":"view",
"name":"社区服务",
"url":"http://www.disga.co/1weixin/index.php"
},
{
"type":"view",
"name":"好邻商城",
"url":"http://www.disga.co/0hlb0/ecwap/"
},
{
"type":"view",
"name":"关于我们",
"url":"http://www.disga.co"
}]
}‘;*/
$jsonmenu = ‘{
"button": [
{
"name": "好邻社区",
"sub_button": [
{
"type": "view",
"name": "进入好邻社区",
"url": "http://www.disga.co/1weixin/index.php",
"sub_button": [ ]
},
{
"type": "click",
"name": "获取我的用户名",
"key": "get_my_user_name",
"sub_button": [ ]
}
]
},
{
"name": "好邻商城",
"sub_button": [
{
"type": "click",
"name": "进入好邻商城",
"key": "enter_shop",
"sub_button": [ ]
}
]
},
{
"name": "关于我们",
"type": "view",
"url": "http://www.disga.co"
}
]
}‘;
$access_token = $this->getAccessToken(APPID,APPSERCRET);
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = $this->https_request($url, $jsonmenu);
return json_decode($result);
}
public function get_menu()
{
$access_token = $this->getAccessToken(APPID,APPSERCRET);
$url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".$access_token;
$result = $this->https_request($url);
return json_decode($result);
}
public function get_user_info($openId)
{
$access_token = $this->getAccessToken(APPID,APPSERCRET);
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$openId."&lang=zh_CN";
$result = $this->https_request($url);
return json_decode($result,true);
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
public function valid()
{
$echostr = $_GET[‘echostr‘];
if($this->checkSignature())
{
echo $echostr;
exit;
}
}
//回复文本消息
public function responseMsg()
{
$post_str = $GLOBALS[‘HTTP_RAW_POST_DATA‘];
if(!empty($post_str))
{
$post_obj = simplexml_load_string($post_str);
switch($post_obj->MsgType)
{
//回复文本消息
case "text":
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$time = time();
$keyword = trim($post_obj->Content);
$res = preg_match($pattern, $keyword,$match);
$pattern = ‘/^绑定@(.*)@(.*)/‘;
if(preg_match($pattern, $keyword,$match))
{
$pattern1 = ‘/^(1(([35][0-9])|(47)|[8][0126789]))\d{8}$/‘;
$res1 = preg_match($pattern1, $match[1],$matches);
if($res1){
//如果手机号码格式正确,到数据库里面查询,是否有这个手机号码
//如果有这个手机号码,将他的用户名插入到数据库里面
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
$sql_verify = "select count(*) as num from pre_user where phone = ‘{$matches[0]}‘";
$result_verify = $db->query($sql_verify);
$res_verify = $db->fetch_array($result_verify);
if($res_verify[‘num‘]>0){
//将该用户的用户名插入到数据库里面去
//得到微信nickname,openId绑定到数据库里面去
$openId = $post_obj->FromUserName;
$user_info = $this->get_user_info($openId);
$nickname = $user_info[‘nickname‘];
$sql_bang = "update pre_user set weixin =‘{$nickname}‘,openId = ‘{$openId}‘ where phone=‘{$matches[0]}‘";
$result_bang = $db->query($sql_bang);
$aff = $db->getAffectedRows();
if($aff>0)
{
$contentStr = "微信号:‘".$nickname."‘和app账号:‘".$matches[0]."‘绑定成功";
}else{
$contentStr = "微信号:‘".$nickname."‘和app账号:‘".$matches[0]."‘已经绑定过了";
}
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$contentStr);
echo $resultStr;
}else{
$contentStr = "该手机号还未注册好邻帮app!";
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$contentStr);
echo $resultStr;
}
}else{
$contentStr = "手机号码格式不对,请从新输入";
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$contentStr);
echo $resultStr;
}
}elseif($keyword == "你好" || $keyword == "您好" || $keyword == ‘在‘)
{
$contentStr = $post_obj->FromUserName." :你想抢劫啊";
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$contentStr);
echo $resultStr;
}elseif($keyword=="绑定"){
$contentStr = ‘欢迎关注【好邻帮】,
它能让你更加方便寻找在你附近合你心意的餐饮、服装、百货、美容美发店铺。
<a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=‘.APPID.‘&redirect_uri=http://120.24.78.29/0hlb0/oauth.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect">点击这里绑定</a>‘;
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$contentStr);
echo $resultStr;
}elseif($keyword == "音乐"){
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Music>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<MusicUrl><![CDATA[http://zj189.cn/zj/download/music/zxmzf.mp3]]></MusicUrl>
<HQMusicUrl><![CDATA[http://zj189.cn/zj/download/music/zxmzf.mp3]]></HQMusicUrl>
</Music>
<FuncFlag>0</FuncFlag>
</xml>";
$time = time();
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"music","海阔天空","演唱者:五月天");
echo $resultStr;
}elseif($keyword == "单图文"){
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title><![CDATA[[苹果产品信息查询]]></Title>
<Description><![CDATA[序列号:USE IMEI NUMBER
IMEI号:358031058974471
设备名称:iPhone 5C
设备颜色:
设备容量:
激活状态:已激活
电话支持:未过期[2014-01-13]
硬件保修:未过期[2014-10-14]
生产工厂:中国]]>
</Description>
<PicUrl><![CDATA[http://img3.qianzhan123.com/news/201412/09/20141209-370b943aec640b1e_580x1300.jpg]]></PicUrl>
<Url><![CDATA[http://www.baidu.com]]></Url>
</item>
</Articles>
<FuncFlag>0</FuncFlag>
</xml>";
$time = time();
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time);
echo $resultStr;
}elseif($keyword=="多图文"){
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>2</ArticleCount>
<Articles>
<item>
<Title><![CDATA[[苹果产品信息查询]]></Title>
<Description><![CDATA[序列号:USE IMEI NUMBER
IMEI号:358031058974471
设备名称:iPhone 5C
设备颜色:
设备容量:
激活状态:已激活
电话支持:未过期[2014-01-13]
硬件保修:未过期[2014-10-14]
生产工厂:中国]]>
</Description>
<PicUrl><![CDATA[http://img3.qianzhan123.com/news/201412/09/20141209-370b943aec640b1e_580x1300.jpg]]></PicUrl>
<Url><![CDATA[http://www.baidu.com]]></Url>
</item>
<item>
<Title><![CDATA[ipad]]></Title>
<Description><![CDATA[budexing]]></Description>
<PicUrl><![CDATA[http://img5.imgtn.bdimg.com/it/u=32493795,959149406&fm=21&gp=0.jpg]]></PicUrl>
<Url><![CDATA[http://www.sohu.com]]></Url>
</item>
</Articles>
<FuncFlag>0</FuncFlag>
</xml>";
$time = time();
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time);
echo $resultStr;
}elseif($keyword == "二维码"){
$access_token = $this->getAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
$data = ‘{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}‘;
$res = $this->https_request($url, $data);
$res = json_decode($res,true);
$ticket = urlencode($res[‘ticket‘]);
$url1 = ‘https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=‘.$ticket;
$res1 = https_request($url1);
}elseif(preg_match(‘/附近(.*)/‘,$keyword,$matches)){
$time = time();
$key = $matches[1];
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
$sql = "select location from pre_location where openId = ‘{$post_obj->FromUserName}‘ limit 1";
$result_sql = $db->query($sql);
$res_sql = $db->fetch_array($result_sql);
$location = $res_sql[‘location‘];
$url = "http://api.map.baidu.com/place/v2/search?ak=osVI9fKD8uWCOPPKOhINzNWN&location=".$location."&output=json&query=".$key."&page_num=1&page_size=10&radius=2000";
$res = $this->https_request($url);
$res =json_decode($res,true);
$tpl_item_one = "
<item>
<Title><![CDATA[附近的".$key."]]></Title>
<Description><![CDATA[]]></Description>
<PicUrl><![CDATA[http://pic4.nipic.com/20091214/3795234_161347041029_2.jpg]]></PicUrl>
<Url><![CDATA[]]></Url>
</item>
";
$tpl_item = " <item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]]></Url>
</item>
";
$item_str = "";
foreach ($res[‘results‘] as $v){
$phone = empty($v[‘telephone‘])?"":"\n电话:".$v[‘telephone‘];
$dis = $v[‘address‘]." ".$phone;
$item_str .= sprintf($tpl_item, $v[‘name‘]."\n".$dis, $dis, "", "");
}
$item_str = $tpl_item_one.$item_str;
$xmlTpl = "
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>%s</ArticleCount>
<Articles>
".$item_str."</Articles>
</xml>";
$resultStr = sprintf($xmlTpl, $post_obj->FromUserName, $post_obj->ToUserName, time(), count($res[‘results‘]));
echo $resultStr;
}else{
$user_info = $this->get_user_info($post_obj->FromUserName);
$date = date("Y-m-d H:i",$user_info[‘subscribe_time‘]);
$contentStr = "您的基本信息如下\n用户名:".$user_info[‘nickname‘]."\n所在地:".$user_info[‘country‘]."-".$user_info[‘province‘]."-".$user_info[‘city‘]."\n关注时间:".$date;
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$contentStr);
echo $resultStr;
}
}
//回复地图消息
case "location":
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$time = time();
$contentStr = "您发送的地址是:\n".$post_obj->Label."\n经度是".$post_obj->Location_X."\n维度是".$post_obj->Location_Y;
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"text",$contentStr);
echo $resultStr;
}
case "image":
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Image>
<MediaId><![CDATA[%s]]></MediaId>
</Image>
</xml>";
$time = time();
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"image",$post_obj->MediaId);
echo $resultStr;
}
case "voice":
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Voice>
<MediaId><![CDATA[%s]]></MediaId>
</Voice>
</xml>";
$time = time();
$contentStr = "你发送的格式是".$post_obj->Format;
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,$post_obj->MsgType,$post_obj->MediaId);
echo $resultStr;
}
case "shortvideo":
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Video>
<MediaId><![CDATA[%s]]></MediaId>
</Video>
</xml>";
$time = time();
$contentStr = "视频MediaId".$post_obj->MediaId;
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"video",$post_obj->MediaId);
echo $resultStr;
}
case "event":
{
if($post_obj->Event == "LOCATION")
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$time = time();
$location = $post_obj->Latitude.",".$post_obj->Longitude;
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
//如果已经有了就进行更新,否则就插入
$sql_verify = "select id from pre_location where openId=‘{$post_obj->FromUserName}‘ ";
$result_verify = $db->query($sql_verify);
$res_verify = $db->fetch_array($result_verify);
if($res_verify){
//进行更新
$sql_up = "update pre_location set location =‘{$location}‘ where openId = ‘{$post_obj->FromUserName}‘";
$result_up = $db->query($sql_up);
$id = $db->getAffectedRows();
}else{
$sql_in = "insert into pre_location(location,openId) values(‘{$location}‘,‘{$post_obj->FromUserName}‘)";
$result_in = $db->query($sql_in);
//$id = $db->getLastId();
}
//将地址存入一处才行
//$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"text",$id);
//echo $resultStr;
}elseif($post_obj->Event == "subscribe"){
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$time = time();
//进行注册操作 ,注册后将信息写入到ucenter表里面 告诉用户用户名
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
$rand1 = range(a,z);
$rand2 =range(0,9);
$rand = array_merge($rand1,$rand2);
$rand = implode(‘‘,$rand);
$salt = substr(str_shuffle($rand),0,6);
$ext = substr(str_shuffle($rand), 0,4);
//对密码进行加密
$passwordmi = md5(md5(‘123456‘).$salt);
//得到用户名
$user_info = $this->get_user_info($post_obj->FromUserName);
$username = $user_info[‘nickname‘]."_".$ext;
$contentStr = "欢迎您关注好邻帮微信公众平台\n您的好邻帮用户名:".$username."\n初始密码密码:123456\n您可以进入好邻社区进行手机绑定与密码修改!";
//$contentStr = "欢迎好邻帮微信服务号,请进行app手机账号绑定,格式(绑定@手机号)";
$sql = "select count(*) as num from pre_ucenter_members where openId=‘{$user_info[‘openid‘]}‘";
$result_sql = $db->query($sql);
$res_sql = $db->fetch_array($result_sql);
$num = $res_sql[‘num‘];
if($num>0){
//如果openid这个字段已经存在了,告诉用户用户名 更新下
$sql_update = "update pre_ucenter_members set weixin=‘{$user_info[‘nickname‘]}‘ where openId=‘{$user_info[‘openid‘]}‘";
$sql_username = "select username from pre_ucenter_members where openId=‘{$user_info[‘openid‘]}‘ ";
$result_username = $db->query($sql_username);
$res_username = $db->fetch_array($result_username);
$username = $res_username[‘username‘];
$contentStr = "欢迎您关注好邻帮微信公众平台\n您的好邻帮用户名:".$username;
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"text",$contentStr);
echo $resultStr;
}else{
$sql1 = "insert into ".UC_PRE."members(openId,weixin,username ,password ,salt,regdate) values(‘{$user_info[‘openid‘]}‘,‘{$user_info[‘nickname‘]}‘,‘{$username}‘,‘{$passwordmi}‘,‘{$salt}‘,‘{$time}‘)";
$res_ucenter = $db->query($sql1);
$dzuserid = $db->getLastId();
$contentStr = "欢迎您关注好邻帮微信公众平台\n您的好邻帮用户名:".$username."\n初始密码密码:123456\n您可以进入好邻社区进行手机绑定与密码修改!";
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"text",$contentStr);
echo $resultStr;
}
}elseif($post_obj->Event =="CLICK")
{
if($post_obj->EventKey == "get_my_user_name")
{
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$time = time();
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
$user_info = $this->get_user_info($post_obj->FromUserName);
$sql = "select username from pre_ucenter_members where openId = ‘{$user_info[‘openid‘]}‘";
$result_sql = $db->query($sql);
$res_sql = $db->fetch_array($result_sql);
if(!empty($res_sql))
{
$username = $res_sql[‘username‘];
$contentStr = "你的用户名是:".$username."\n初始密码为:123456";
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"text",$contentStr);
echo $resultStr;
}
}elseif($post_obj->EventKey == "enter_shop")
{
//点击的时候 返回一个链接,点击链接进行登录
$tpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$time = time();
require_once ‘../demo/app/class/db.class.php‘;
$db = new DB();
$user_info = $this->get_user_info($post_obj->FromUserName);
$sql = "select username from pre_ucenter_members where openId = ‘{$user_info[‘openid‘]}‘";
$result_sql = $db->query($sql);
$res_sql = $db->fetch_array($result_sql);
if(isset($res_sql[‘username‘]))
{
$username = $res_sql[‘username‘];
$password = "123456";
$url = "http://120.24.78.29/0hlb0/ecwap/index.php?app=member&act=login&ret_url=http://120.24.78.29/0hlb0/ecwap/";
$contentStr = "<a href = ‘http://120.24.78.29/0hlb0/ecwap/index.php?app=member&act=login&ret_url=&user_name=".$username."&password=123456‘>点击进入 </a>好邻商城";
$resultStr = sprintf($tpl,$post_obj->FromUserName,$post_obj->ToUserName,$time,"text",$contentStr);
echo $resultStr;
}
}
}
}
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/php-linux/p/4580291.html