微信公众账号平台已经非常火爆了,入驻的用户群已经非常庞大了。今天也非常荣幸成为其中一员,因为本身是开发人员,所以开通了开发中心接口,现在把服务配置纪录下来,方便后面加入的朋友学习。对了,这个仅对有自己服务器的用户有效,或者你有免费的服务器也OK!
下面说说操作,成功登录公众账号之后左边菜单最下面有一个开发者中心,如图
下面说说操作,成功登录公众账号之后左边菜单最下面有一个开发者中心,如图


valid();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "
%s
0
";
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;
}
}
private function checkSignature()
{
// you must define TOKEN by yourself
if (!defined("TOKEN")) {
throw new Exception('TOKEN is not defined!');
}
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = 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;
}
}
}
?>
是不是非常的简单呢,后面自定义菜单和推送数据慢慢再帖出来! 收藏的用户(0) X
正在加载信息~
推荐阅读
站点信息
- 文章2313
- 用户1336
- 访客11761708
每日一句
Life's best gifts come from hard work.
生命最珍贵的馈赠源于辛勤耕耘。
生命最珍贵的馈赠源于辛勤耕耘。
Project Treble让Android更新速度更快
【转载】cocos2d-x 3.0 制作横版格斗游戏
C++实现UDP打洞
java.nio.ByteBuffer缓冲区简介
Android Studio使用Eclipse的debug.keystore
#ifdef _DEBUG失效问题
Cocos2d-x 3.17.2和Android Studio环境搭建
Android studio中.9图片的制作
8个开发人员都应该知道的Android 库
从simplepjsua.c示例程序了解PJSUA-LIB的基本使用流程
【转载】C++实现EXE加载到内存执行
关于Android Studio不能查看源码
未来在线学习的5个优势
新会员