Current location - Quotes Website - Signature design - Thinkphp3.2.3 can't always access the official account of WeChat to respond to the token authentication sent by WeChat.
Thinkphp3.2.3 can't always access the official account of WeChat to respond to the token authentication sent by WeChat.
Do you need to judge that token? Isn't it necessary? Use this one of mine to ensure your satisfaction.

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

Namespace? Home \ Controller;

Use? Thinking \ controller;

Class? IndexController? Extension? Wechat controller? {

Public? Function? index(){

$v? =? $ _ GET[" echostr "];

If (! Isset($v)){// Judge whether it has been verified before according to the random string to avoid repeated verification.

$ this-& gt; receive();

} Otherwise {

$ this-& gt; check signature();

}

}

//Not Verified Perform verification

Public? Function? checkSignature(){

$ signature? =? I ("signature"); //Encrypted signature

$ time stamp? =? I ("timestamp"); //timestamp

$nonce? =? I(" nonce "); //Random number

$token? =? TOKEN// token

$tmpArr? =? Array ($token, $timestamp,? $ nonce); //Form a new array

sort($tmpArr,SORT _ STRING); //Reorder

$tmpStr? =? $ TERM parr; //Convert to a string

$tmpStr? =? sha 1($ tmp str); //Then encrypt the string.

If (? $tmpStr? ==? $ signature? )

{

Echo? $ _ GET[" echostr "];

Quit;

//Return? True;

} Otherwise {

Return? Fake;

}

}

//Verification has been performed here.

Public? Function? Receive () {

$postStr? =? $ GLOBALS[" HTTP _ RAW _ POST _ DATA "]; //Get the message in xml format sent by the user.

//$postStr? =? file _ get _ contents(" PHP://input ");

libxml _ disable _ entity _ loader(true);

$postObj? =? simplexml_load_string($postStr,? " SimpleXMLElement ",LIBXML _ NOCDATA);

$ this-& gt; logger($ postStr);

//and reply the information to the user.

If (! empty($postObj)){

Switch ($ post obj-& gt;; MsgType){

Case? "Text":

$ Results? =? $ this-& gt; receive text($ post obj);

//Avoid false information reporting.

if(empty($result)){

$xml? =? “& ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& lt content & gt& lt! [CDATA[% s]]& gt; & lt/Content & gt;

& lt/XML & gt; ";

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName,time(),$ postObj-& gt; MsgType, "Don't get multi-graph information");

}

Echo? $ result

Break;

Case? [Image]:

$ Results? =? $ this-& gt; receive image($ post obj);

if(empty($result)){

$xml? = " & ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& ltArticleCount & gt 1 & lt; /article count & gt;

& lt articles & gt

& ltitem & gt

& ltTitle & gt& lt! [CDATA[% s]]& gt; & lt/Title & gt; ?

& lt description & gt& lt! [CDATA[% s]]& gt; & lt/Description & gt;

& ltPicUrl & gt& lt! [CDATA[% s]]& gt; & lt/pic URL & gt;

& ltUrl & gt& lt! [CDATA[% s]]& gt; & lt/Url & gt;

& lt/item & gt;

& lt/Articles & gt;

& lt/XML & gt; ";

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), News, Let's do WeChat development with Lao Li, WeChat development is the development of WeChat public platform, which displays enterprise information, services, activities and other contents through WeChat webpage, and users can generate WeChat 3G website through simple settings. Show the corporate brand to WeChat users through the WeChat public platform, reduce the publicity cost, establish one-to-one interaction and communication among enterprises, consumers and customers, and connect consumers to the enterprise CRM system for promotion, promotion, publicity and after-sales. It has formed a mainstream online and offline WeChat interactive marketing method. ”、"/-po 3d sag _ xi4khgkpowk 1hf 6 hy/baike/w % 3d 268% 3Bg % 3d 0/sign = a 1070 f 75 17 DFA 9 ecfd 2 e 5 1 1 5aeb 903 e/b 03533 fa 828 ba 6 1 efb 07 a 5464738

}

Echo? $ result

Break;

Case? "event":

$ Results? =? $ this-& gt; receive event($ post obj);

if(empty($result)){

$xml? =? “& ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& lt content & gt& lt! [CDATA[% s]]& gt; & lt/Content & gt;

& lt/XML & gt; ";

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "Thank you for paying attention to the WeChat interface test service number. I'm Miss Li!" );

}

Echo? $ result

Break;

Default? :

$ Results? =? "The data type you sent will not be processed for the time being:?" ? . ? $ post obj-& gt; MsgType

Echo? $ result

Break;

}

}

}

//log

Private? Function? Recorder ($ content)

$ logSize = 100000;

$log? =? "./log . txt ";

if(file_exists($log)? & amp& amp? File size (log)? & gt? $logSize){

unlink($ log);

}

File _ upload _ content ($log,? Date ("Y-m-d? H:i:s”)。 "?" . $ content. " \n ",FILE _ APPEND);

}

//Pay attention to automatic reply information

Private? Function? Receive event ($ postobj)

$xml? =? “& ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& lt content & gt& lt! [CDATA[% s]]& gt; & lt/Content & gt;

& lt/XML & gt; ";

if($ post obj-& gt; Event=="subscribe"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "Thank you for paying attention to the WeChat interface test service number. I'm Miss Li!" );

} something else? if($ post obj-& gt; Event=="CLICK"){

if($ post obj-& gt; EventKey=="getSalary"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You clicked the query-> Salary button ");

} something else? if($ post obj-& gt; EventKey=="getAttendance"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You clicked the query-> Attendance record button ");

} something else? if($ post obj-& gt; EventKey=="getBonus"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You clicked the query-> Bonus details button ");

} something else? if($ post obj-& gt; EventKey=="getAbout"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You clicked about us-> Contact button ");

} something else? if($ post obj-& gt; EventKey=="getJoin"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You clicked about us-> Join us button ");

} something else? if($ post obj-& gt; EventKey=="getCustomer"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You clicked about us-> Customer service button ");

} something else? if($ post obj-& gt; EventKey=="getInternational"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You ordered the news-> International button ");

} something else? if($ post obj-& gt; EventKey=="getIndustry"){

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You ordered the news-> Industry button ");

}

} something else? if($ post obj-& gt; Event=="scancode_waitmsg"){

//Scan event codes with prompts

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You used a code scanning event with prompt, and the event key is {$ postobj-> eventkey}";

} something else? if($ post obj-& gt; Event=="scancode_push"){

//Scan code push event

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "You pushed the event with scan code, and the event key: {$ postobj->; event key }”);

} Otherwise {

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), "text", "Your operation is a bit wonderful");

}

Return? $ result

}

//Process the received text information and reply to the user.

Private? Function? receiveText($postObj){

$ content? =? trim($ post obj-& gt; Content);

//if(strstr($content," hello "){

if(preg_match("/^\d*$/",$content)){

//Reply to multi-picture information

$ Results? =? $ this-& gt; receive news($ post obj);

Return? $ result?

} something else? If($content== "picture") {

//Reply to the picture information

$xml? =? “& ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& ltImage & gt

& ltMediaId & gt& lt! [CDATA[% s]]& gt; & lt/MediaId & gt;

& lt/Image & gt;

& lt/XML & gt; ";

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName,time()," image "," t 8 aswvxml 1 vypfmdznezlq 2 z 2 b 6 WIM 4 Ji 4 PBC 23 qumuc 9 1 T9 nm 1 gwfgajcdumv-");

Return? $ result

} Otherwise {

//Reply to SMS

$xml? =? “& ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& lt content & gt& lt! [CDATA[% s]]& gt; & lt/Content & gt;

& lt/XML & gt; ";

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName,time(),$ postObj-& gt; MsgType,$ content);

Return? $ result

}

}

//Process the received text message and reply it to the user as a single text message.

Private? Function? Received image ($ postobj)

$xml? = " & ltxml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& ltArticleCount & gt 1 & lt; /article count & gt;

& lt articles & gt

& ltitem & gt

& ltTitle & gt& lt! [CDATA[% s]]& gt; & lt/Title & gt; ?

& lt description & gt& lt! [CDATA[% s]]& gt; & lt/Description & gt;

& ltPicUrl & gt& lt! [CDATA[% s]]& gt; & lt/pic URL & gt;

& ltUrl & gt& lt! [CDATA[% s]]& gt; & lt/Url & gt;

& lt/item & gt;

& lt/Articles & gt;

& lt/XML & gt; ";

$ Results? =? sprintf($xml,$ post obj-& gt; FromUserName,$ post obj-& gt; ToUserName, time (), News, Let's do WeChat development with Lao Li, WeChat development is the development of WeChat public platform, which displays enterprise information, services, activities and other contents through WeChat webpage, and users can generate WeChat 3G website through simple settings. Show the corporate brand to WeChat users through the WeChat public platform, reduce the publicity cost, establish one-to-one interaction and communication among enterprises, consumers and customers, and connect consumers to the enterprise CRM system for promotion, promotion, publicity and after-sales. It has formed a mainstream online and offline WeChat interactive marketing method. ”、"/-po 3d sag _ xi4khgkpowk 1hf 6 hy/baike/w % 3d 268% 3Bg % 3d 0/sign = a 1070 f 75 17 DFA 9 ecfd 2 e 5 1 1 5aeb 903 e/b 03533 fa 828 ba 6 1 efb 07 a 5464738

Return? $ result

}

//Process the received text information and reply it to the user as multi-picture information.

Private? Function? Receive news ($ postobj) (

$con? =? Array (

array(" Title " = >; "Guanqian Street", "Description" =>" hjhhj ", " PicUrl " = & gt"/9fo 3d sag _ Xi 4k hgko 9 wtanf 6h hy/image/pic/item/5243 fbf2b 2 1 193 1382 f8e 07 1 6c 380 CD 790238 db 3 . jpg "," Url " = & gt"/9 fo 3d sag _ Xi 4k hgko 9 wtanf 6h hy/image/pic/item/5243 fbf2b 2 1 193 1382 f8e 07 16c 380 CD 790238 db 3 . jpg "),

array(" Title " = >; "Pingjiang Road", "Description" = >; " mkbkbjj "," PicUrl " = & gt"/upload/ttq/20 160729/ 146978 1927056 . JPEG "," Url"= >"/upload/ttq/20 160729/ 146978 1927056 . JPEG "),

array(" Title " = >; "Pingjiang Road", "Description" = >; " mkbkbjj "," PicUrl " = & gt"/html/UploadPic/20 10-3/20 1033 173945493 . jpg "," Url " = & gt"/html/UploadPic/20 10-3/20 1033 173945493 . jpg "),

array(" Title " = >; "Guanqian Street", "Description" =>" hjhhj ","PicURL "=>"/Uploadfile/2013/0508/20130508/kloc-0. " Url " = & gt"/uploadfile/20 13/0508/20 130508 102432 19 1 . jpg "),

array(" Title " = >; "Pingjiang Road", "Description" = >; " mkbkbjj "," PicUrl " = & gt"/it/u=995757682,3656700920 & amp; FM = 2 14 & amp; gp=0.jpg "," Url " = & gt"/it/u=995757682,3656700920 & amp; FM = 2 14 & amp; gp=0.jpg "),

array(" Title " = >; "guanqian street", "description" =>" hjhhj ","picurl "=>"/tupian/201261510566.jpg ","Url "= >;; "/tupian/20 126 15 10566 . jpg "),

array(" Title " = >; "Pingjiang Road", "Description" = >; " mkbkbjj "," PicUrl " = & gt"/uploads/allimg/ 160528/9- 16052 q 54439-50 . jpg "," Url " = & gt"/uploads/allimg/ 160528/9- 16052 q 54439-50 . jpg ")

);

$ bodys = " & ltitem & gt

& ltTitle & gt& lt! [CDATA[% s]]& gt; & lt/Title & gt;

& lt description & gt& lt! [CDATA[% s]]& gt; & lt/Description & gt;

& ltPicUrl & gt& lt! [CDATA[% s]]& gt; & lt/pic URL & gt;

& ltUrl & gt& lt! [CDATA[% s]]& gt; & lt/Url & gt;

& lt/item & gt; ";

$tpl2? ="";

foreach($con? As? $ key = & gt$newArray)? {

$tpl2? . =? sprintf($bodys,$newArray["Title"],$newArray["Description"],$newArray["PicUrl"],$ new array[" Url "]);

}

$fromUsername? =? $ post obj-& gt; From user name;

$toUsername? =? $ post obj-& gt; ToUserName

$ TPL 1 = " & lt; xml & gt

& ltToUserName & gt& lt! [CDATA[% s]]& gt; & lt/touser name & gt;

& ltfrom user name & gt& lt! [CDATA[% s]]& gt; & lt/from username & gt;

& ltCreateTime & gt% s & lt/create time & gt;

& ltMsgType & gt& lt! [CDATA[% s]]& gt; & lt/msg type & gt;

& ltArticleCount & gt% s & lt/article count & gt;

& lt article & gt ";

$ tpl3 = " & lt/Articles & gt;

& lt/XML & gt; ";

$ TPL 1 = sprintf($ TPL 1,$fromUsername,$toUsername,time()," news ",count($ con));

$ Results? =? $tpl 1。 $tpl2。 $ tpl3

Return? $ result

}

}