項目案例:微信搜索”啟德國際教育“或掃描二維碼

開發周期:2013-06~2013-08
參與人員:bqq,hongye
主要功能:
01)微信的自動回復(文本,圖文,音頻)
02)微信自定義菜單
03)微視頻,瘋狂猜單詞,瘋狂聽單詞,賬號綁定CRM,啟德名師,高分學員,院校庫等模塊上線
04)手機通過微信綁定后,將微信賬號反推至CRM
05)教務系統調課,根據調課事件推送微信消息至相關人員
看到那些熱心的朋友:http://118.186.246.148/bqqpay/給予幫助和支持,真的很感激,也希望各位早日脫離屌絲,走向小康,謝謝!
好了,廢話少說,說說注意事項,解析代碼吧(以我的案例):
注意事項:
一,如果你沒有公眾賬號,且未經認證,建議別玩,因為你很難玩轉,項目公眾平臺截圖

二,必須開啟開發模式,編輯模式有意思嗎?那是小編干的活,

三,配置信息很重要,你會用到的,URL就是你部署的地址,我的馬賽克打的何如?

四,好好看看接口文檔吧,如果需要開啟更多功能,請呼叫馬化騰,

代碼解析:
include("weixin.php");
require_once 'hyphp/config.ini.php';//調用自定義配置文件
define("ACCOUNT", "");//微信公眾平臺的用戶名
define("PASSWORD", "");//微信公眾平臺的密碼
define("TOKEN", "");//開發模式的TOKEN碼
define('DEBUG', true);//是否開啟調試模式
$param = array('username'=>'微信公眾平臺的用戶名', 'pwd'=>'微信公眾平臺的密碼');
$weixin = new Weixin(TOKEN,DEBUG);
if($weixin->login($param)){
你可以猥瑣欲為了,哈哈哈哈
}
else{
配置信息不對,別想模擬登錄
}
如果你需要自定義菜單,就生成吧,我寫在這里做了注釋,因為一般只需要生成一次即可,除非你老是修改菜單,生成后,不會立即顯示,因為有24小時的緩存,除非你取消關注,然后重新關注即可!
/*生成自定義菜單開始*/
/*$xjson = '{
"button":[
{
"name":"籃球",
"sub_button":[
{
"type":"click",
"name":"nba",
"key":"V1001_NBA"
},
{
"type":"click",
"name":"cba",
"key":"V1001_CBA"
}
]
},
{
"name":"體育",
"sub_button":[
{
"type":"click",
"name":"足球",
"key":"V1001_ZUQIU"
},
{
"type":"click",
"name":"排球",
"key":"V1001_PAIQIU"
},
{
"type":"click",
"name":"網球",
"key":"V1001_WANGQIU"
},
{
"type":"click",
"name":"乒乓球",
"key":"V1001_PPQ"
},
{
"type":"click",
"name":"臺球",
"key":"V1001_TAIQIU"
}
]
},
{
"name":"新聞",
"sub_button":[
{
"type":"click",
"name":"國內新聞",
"key":"V1001_GNNEWS"
},
{
"type":"click",
"name":"國際新聞",
"key":"V1001_GJNEWS"
},
{
"type":"click",
"name":"地方新聞",
"key":"V1001_AREANEWS"
},
{
"type":"click",
"name":"家庭新聞",
"key":"V1001_HOMENEWS"
}
]
}
]
}';
$jsonMenu = json_encode($xjson);
$get_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=開發者模式中的AppId串&secret=開發者模式中的AppSecret串';
$get_return = file_get_contents($get_url);
$get_return = (array)json_decode($get_return);
if( !isset($get_return['access_token']) ){exit( '獲取access_token失敗!' );}
$post_url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$get_return['access_token'];
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$xjson);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($xjson))
);
$respose_data = curl_exec($ch);
echo $respose_data;exit;*/
/*生成自定義菜單結束*/
你會看懂的,點擊菜單事件回復,文本消息回復,智能語音識別
$weixin->getMsg();
$type = $weixin->msgtype; //消息類型
$username = $weixin->msg['FromUserName'];//哪個用戶給你發的消息,這個$username是微信加密之后的,每個用戶都是一一對應的
if ($type === 'event') {//點擊菜單事件
$eventkey = $weixin->eventkey;//獲取當前菜單key
if($eventkey=='V1001_NBA') {
$hongye_bqq = '您點擊的NBA菜單,哈哈';
}
if($eventkey=='V1001_CBA') {
$hongye_bqq = '您點擊的CBA菜單,哈哈';
}
else{
$hongye_bqq = '歡迎關注bqq!';
}
}
if ($type === 'text') {//文本輸入
$kwds=$weixin->msg['Content'];
$sql="select * from `wx_text_msg` where `question` like '%$kwds%' ";
$res=getOne($sql);
if($res) {
$reply = $weixin->makeText($res['answer']);
}
else{
$reply = $weixin->makeText('抱歉,根據您輸入的文本,暫時未找到相關匹配信息');
}
}
if ($type === 'voice') {//語音輸入
$kwds = substr($weixin->msg['Recognition'],0,-3);
$sql="select * from `wx_voice_msg` where `question` like '%$kwds%' ";//根據語音輸入關鍵詞,查詢數據表匹配答案
$res=getOne($sql);
if($res) {
$reply = $weixin->makeText($res['answer']);
}
else{
$reply = $weixin->makeText('抱歉,根據您輸入的語音,暫時未找到相關匹配信息');
}
}
$weixin->reply($reply);