Public Platform DEMO (PHP) and public demo. Public Platform DEMO (PHP), public demo I set up the CI framework in the SAE environment (in fact, this little thing does not need to use the framework), directly write the code in the controller phpif (! Def public platform DEMO (PHP), public demo
I set up the CI framework in the SAE environment (in fact, this little thing does not need to use the framework) and directly wrote the code in the controller.
<? Php if (! Defined ('basepath') exit ('no direct script access allowed'); // define your tokendefine ("TOKEN", "109 "); class Welcome extends CI_Controller {public function index () {/* $ this-> load-> helper ('URL '); $ this-> load-> view ('Welcome _ message'); * // use chat response $ this-> responseMsg ();} // chat response public function responseMsg () {// get post data, May be due to the different environments $ postSt R = $ GLOBALS ["HTTP_RAW_POST_DATA"]; // extract post data if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ fromUsername = $ postObj-> FromUserName; $ toUsername = $ postObj-> ToUserName; $ MsgType = $ postObj-> MsgType; $ time = time (); switch ($ MsgType) {case ('text '): $ keyword = trim ($ postObj-> Content); $ textTpl ="
%s
%s
% S
%s
%s
"; Switch ($ keyword) {case (1): // Need to optimize // random read data from jokes $ SQL = 'select * FROM joks '; $ query = $ this-> db-> query ($ SQL); $ res = $ query-> result_array (); $ num_rows = $ query-> num_rows (); $ key = rand (0, $ num_rows-1); // Notice: The value of key is from 0. // $ contentStr = $ key. '#'. $ res [$ key] ['content']; // debug $ contentStr = $ res [$ key] ['content']; break; case (2 ): $ contentStr = 'Your fromUsername is :'. $ fromUsername; break; case (3): $ newsTpl ="
%s
%s
% S
%s
2
<! [CDATA [% s]>
%s
%s
%s
<! [CDATA [% s]>
%s
%s
%s
"; $ ResultStr = sprintf ($ newsTpl, $ fromUsername, $ toUsername, $ time, 'news', 'Baidu ','',' http://www.baidu.com /Img/bdlogo.gif ',' http://www.baidu.com ', 'Google ','','',' http://www.google.com '); // Notice: Google's logo is not suitable. echo $ resultStr; exit; // Notice: It's exit, not break. case (4): $ contentStr = "this function is under development. please wait... "; break;/* others */default: $ contentStr =" reply number selection service \ n "; $ contentStr. = "1 joke featured \ n"; $ contentStr. = "2 get your Username... \ n "; $ contentStr. = "3 graphic message example \ n"; $ contentStr. = "4 developing... \ n "; break;} $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, 'text', $ contentStr); break; case ('image '): $ media_id = $ postObj-> MediaId; $ imgTpl ="
%s
%s
% S
%s
%s
"; $ ResultStr = sprintf ($ imgTpl, $ fromUsername, $ toUsername, $ time, 'Image', $ media_id); break; // try get the id of the receive image and analyze/* $ media_id = $ postObj-> MediaId; $ textTpl ="
%s
%s
% S
%s
%s
"; $ Length = strlen ($ media_id); $ contentStr =" I have received the image message you sent, the id of this image is # $ media_id #, and the length of media_id is # $ length # "; $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, 'text', $ contentStr); break; */case ('Voice '): $ textTpl ="
%s
%s
% S
%s
%s
"; $ ContentStr = 'what do you mean? I can't hear you... '; $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, 'text', $ contentStr); break;/* others */default: $ resultStr = "Input something... "; break;} echo $ resultStr;} else {echo"; exit ;}}}
Ghost (PHP), the public demo I set up the CI framework in the SAE environment (in fact, this little thing does not need to use the framework), directly write the code in the controller php if (! Def...