|
一、寫好接口程序
在你的服務器上上傳好一個接口程序文件,如http://www.yourdomain.com/weixin.php 內容如下:
復制代碼 代碼如下:<?php
define("TOKEN", "weixin");//自己定義的token 就是個通信的私鑰
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
//$wechatObj->responseMsg();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$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 = '你好啊,
主站蜘蛛池模板:
安溪县|
宜阳县|
西宁市|
灵台县|
海城市|
兴隆县|
若尔盖县|
仙桃市|
汉寿县|
义马市|
大丰市|
仲巴县|
革吉县|
玉林市|
崇左市|
皋兰县|
资中县|
长治市|
深圳市|
浦县|
吴川市|
濉溪县|
蒲江县|
特克斯县|
乐清市|
清流县|
凤翔县|
金阳县|
垫江县|
玛纳斯县|
历史|
阿克|
建水县|
浙江省|
普陀区|
双峰县|
千阳县|
闽侯县|
静宁县|
留坝县|
元氏县|