|
導讀微信(WeChat)是騰訊公司于2011年1月21日推出的一個為智能終端提供即時通訊服務的免費應用程序,由張小龍所帶領的騰訊廣州研發中心產品團隊打造 [2] 。微信支持跨通信運營商、跨操作系統平臺... 微信(WeChat)是騰訊公司于2011年1月21日推出的一個為智能終端提供即時通訊服務的免費應用程序,由張小龍所帶領的騰訊廣州研發中心產品團隊打造 [2] 。微信支持跨通信運營商、跨操作系統平臺通過網絡快速發送免費(需消耗少量網絡流量)語音短信、視頻、圖片和文字,同時,也可以使用通過共享流媒體內容的資料和基于位置的社交插件“搖一搖”、“漂流瓶”、“朋友圈”、”公眾平臺“、”語音記事本“等服務插件。 微信公眾平臺,給個人、企業和組織提供業務服務與用戶管理能力的全新服務平臺。微信公眾平臺主要有實時交流、消息發送和素材管理。用戶可以對公眾賬戶的粉絲分組管理、實時交流,同時也可以使用高級功能-編輯模式和開發模式對用戶信息進行自動回復。《傳智、黑馬微信公眾平臺開發視頻教程》是由傳智播客和黑馬程序員聯合出品的微信公眾平臺開發視頻教程。
課程播放地址:http://www.php.cn/course/320.html 該老師講課風格: 講課親切自然,樸實無華,沒有矯揉造作,也不刻意渲染,而是娓娓而談,細細道來,師生之間在一種平等、協作、和諧的氣氛下,進行默默的情感交流,將對知識的渴求和探索融于簡樸、真實的教學情景之中,學生在靜靜的思考、默默的首肯中獲得知識 本視頻中較為難點是微信API接口分析了: 微信入口綁定,微信事件處理,微信API全部操作包含在這些文件中。 1. index.php <?php
include_once 'lib.inc.php';
$wcObj = new WeChat("YOUKUIYUAN");
$wcObj->wcValid();2. 微信入口類 <?php
/**
* Description of wechat
*
* @author Administrator
*/
class WeChat extends WxApi{
public $token = "";
//put your code here
public function __construct($token = "") {
parent::__construct();
$this->token = $token;
}
public function wcCheckSignature(){
try{
if (empty($this->token)) {
throw new Exception('TOKEN is not defined!');
}
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = $this->token;
$tmpArr = array($token, $timestamp, $nonce);
// use SORT_STRING rule
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
}
public function wcValid(){
$echoStr = isset($_GET["echostr"]) && !empty($_GET["echostr"]) ? addslashes($_GET["echostr"]) : NULL;
if(is_null($echoStr)){
$this->wcMsg();
}
else{
//valid signature , option
if($this->wcCheckSignature()){
echo $echoStr;
exit;
}
else{
exit();
}
}
}
public function wcMsg(){
//get post data, May be due to the different environments
$postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) && !empty($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
if(!empty($postStr)){
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->zcLog(TRUE,$postObj);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$MsgType = $postObj->MsgType;
if($MsgType == 'event'){//執行事件相應
$Event = $postObj->Event;
switch ($Event) {
case 'subscribe'://關注
break;
case 'unsubscribe'://取消關注
break;
case 'SCAN'://掃描
break;
case 'LOCATION'://地址
break;
case 'CLICK'://點擊時間
break;
case 'VIEW'://跳轉
break;
case 'card_pass_check'://卡券審核通過
break;
case 'card_not_pass_check'://卡券審核失敗
break;
case 'user_get_card'://用戶領取卡券
break;
case 'user_del_card'://用戶刪除卡券
break;
case 'user_view_card'://用戶瀏覽會員卡
break;
case 'user_consume_card'://用戶核銷卡券
break;
case 'merchant_order'://微小店用戶下單付款
break;
default:
break;
}
}
else{
switch ($MsgType) {
case 'text'://文本格式
break;
case 'image'://圖片格式
break;
case 'voice'://聲音
break;
case 'video'://視頻
break;
case 'shortvideo'://小視頻
break;
case 'location'://上傳地理位置
break;
case 'link'://鏈接相應
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if(!empty( $keyword )){
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
else{
echo "Input something...";
}
////////////////////////////////////////////////////////////////////
}
else{
echo "暫時沒有任何信息!";
exit;
}
}
//日志LOG
public function zcLog($errcode , $errmsg){
$this->returnAy = array();
$this->returnAy['errcode'] = $errcode;
$this->returnAy['errmsg'] = $errmsg;
$this->returnAy['errtime'] = date("Y-m-d H:i:s",time());
$logfile = fopen("logfile_".date("Ymd",time()).".txt", "a+");
$txt = json_encode($this->returnAy)."\n";
fwrite($logfile, $txt);
fclose($logfile);
//return $this->returnAy;
}
}以上就是傳智和黑馬的微信公眾平臺開發視頻教程資源推薦的詳細內容,更多請關注php中文網其它相關文章! 微信提供公眾平臺、朋友圈、消息推送等功能,用戶可以通過“搖一搖”、“搜索號碼”、“附近的人”、掃二維碼方式添加好友和關注公眾平臺,同時微信將內容分享給好友以及將用戶看到的精彩內容分享到微信朋友圈。 |
溫馨提示:喜歡本站的話,請收藏一下本站!