Beispiel #1
0
 public function dotext($keyword, $fromUsername)
 {
     $go = new Trans();
     $keyword = $go->t2c($keyword);
     //database
     $ctype = 'general';
     $contentStr = '';
     $moretext = '';
     if (strlen($keyword) > 0) {
         $flag = secret_getflag($fromUsername);
         if ($flag == SECRET_TEXT) {
             secret_inserttext($fromUsername, $keyword);
             $user = secret_gettouser($fromUsername);
             $contentStr = "发送成功!\n如果TA也关注我,\n输入 @" . $user . " 就可以看到你的匿名纸条啦。快让身边的人也来吐露心声吧~~\n";
             $contentStr .= secret_ending();
             secret_updateflag($fromUsername, 0);
         } else {
             //查看最新
             if (preg_match("/^kk([\\s\\S]*)\$/", trim(strtolower($keyword)), $match)) {
                 $contentStr = secret_latestwords($fromUsername);
                 $ctype = 'kk';
             } else {
                 if ($keyword == '有缘人') {
                     $contentStr = secret_wordsbyuser(trim($match[1]));
                 } else {
                     if (preg_match("/^mm([\\s\\S]*)\$/", trim(strtolower($keyword)), $match)) {
                         secret_updateflag($fromUsername, MM_TEXT);
                         secret_inserttouser($fromUsername, '有缘人');
                         $contentStr = "现在以@开头输入你想说的话, 可以说个笑话或者分享一段糗事啊或者分享你的心情,\n而且记得加上联系方式哦~ \nQQ、邮箱、微信号都行啦 这样有缘人才能联系上你~~" . "\n\n输入  @有缘人  查看最新发布";
                         $ctype = 'mm';
                     } else {
                         if (preg_match("/^kta([\\s\\S]*)\$/", trim(strtolower($keyword)), $match)) {
                             secret_updateflag($fromUsername, SECRET_KTA);
                             $contentStr = "以@开头,输入想要查看的的名字,如输入:\n@李小四";
                             $ctype = 'kta';
                         } else {
                             if (preg_match("/^ta([\\s\\S]*)\$/", trim(strtolower($keyword)), $match)) {
                                 secret_updateflag($fromUsername, SECRET_TA);
                                 $contentStr = "以@开头,先输入TA的名字,如输入:\n@李小四";
                                 $ctype = 'ta';
                             } else {
                                 if (preg_match("/^@([\\s\\S]+)\$/", trim($keyword), $match)) {
                                     if (strlen(trim($match[1])) == 0) {
                                         $contentStr = "请在@后面加上名字哦~\n";
                                         $contentStr .= secret_ending();
                                     } else {
                                         if (trim($match[1]) == '有缘人') {
                                             $contentStr = secret_wordsbyuser(trim($match[1]));
                                         } else {
                                             if ($flag == MM_TEXT) {
                                                 secret_inserttext($fromUsername, trim($match[1]));
                                                 $contentStr = "发送成功!\n你的有缘人看到了 一定会联系你的!!\n";
                                                 $contentStr .= secret_ending();
                                                 secret_updateflag($fromUsername, 0);
                                             } else {
                                                 if (strstr(trim($match[1]), ' ') && strpos(trim($match[1]), ' ') < 6) {
                                                     $index = strpos(trim($match[1]), ' ');
                                                     $touser = substr(trim($match[1]), 0, $index);
                                                     secret_inserttouser($fromUsername, $touser);
                                                     secret_inserttext($fromUsername, trim($match[1]));
                                                     if ($touser == '有缘人') {
                                                         $contentStr = "发送成功!\n你的有缘人看到了 一定会联系你的!!\n";
                                                     } else {
                                                         $contentStr = "发送成功!\n如果TA也关注我,\n输入 @" . $touser . " 就可以看到你的匿名纸条啦。快让身边的人也来吐露心声吧~~\n";
                                                     }
                                                     $contentStr .= secret_ending();
                                                     secret_updateflag($fromUsername, 0);
                                                 } else {
                                                     if (mb_strlen(trim($match[1]), 'utf-8') > 8) {
                                                         $touser = '******';
                                                         $index = strpos(trim($match[1]), ' ');
                                                         if ($index != null && index < 6) {
                                                             $touser = substr(trim($match[1]), 0, $index);
                                                         } else {
                                                             $index = strpos(trim($match[1]), ',');
                                                             if ($index != null && index < 6) {
                                                                 $touser = substr(trim($match[1]), 0, $index);
                                                             }
                                                         }
                                                         secret_inserttouser($fromUsername, $touser);
                                                         secret_inserttext($fromUsername, trim($match[1]));
                                                         if ($touser == '有缘人') {
                                                             $contentStr = "发送成功!\n你的有缘人看到了 一定会联系你的!!\n";
                                                         } else {
                                                             $contentStr = "发送成功!\n如果TA也关注我,\n输入 @" . $touser . " 就可以看到你的匿名纸条啦。快让身边的人也来吐露心声吧~~\n";
                                                         }
                                                         $contentStr .= secret_ending();
                                                         secret_updateflag($fromUsername, 0);
                                                     } else {
                                                         if ($flag == SECRET_KTA) {
                                                             $contentStr = secret_wordsbyuser(trim($match[1]));
                                                         } else {
                                                             if ($flag == SECRET_TA) {
                                                                 secret_updateflag($fromUsername, SECRET_TEXT);
                                                                 secret_inserttouser($fromUsername, trim($match[1]));
                                                                 $contentStr = '现在输入你想说的话,可以留下署名哦 这样可能会有人回复你呢';
                                                             } else {
                                                                 $contentStr = secret_wordsbyuser(trim($match[1]));
                                                                 //	$contentStr = secret_welcome();
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     $ctype = '@';
                                 } else {
                                     if (strtolower($keyword) == 'jx' || strstr($keyword, "匿名小纸条")) {
                                         $contentStr = secret_welcome();
                                         $ctype = 'jx';
                                     } else {
                                         $webchat_textmsgObj = new webchat_textmsg();
                                         list($contentStr, $ctype) = $webchat_textmsgObj->dotext($keyword, $fromUsername);
                                         if ($flag == MM_TEXT && mb_strlen($keyword, 'utf-8') > 10) {
                                             $touser = '******';
                                             secret_inserttouser($fromUsername, $touser);
                                             secret_inserttext($fromUsername, $keyword);
                                             $contentStr .= "\n-----------\n发送成功!\n你的有缘人看到了 一定会联系你的!!\n";
                                             secret_updateflag($fromUsername, 0);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $namesArray = array('傻逼', '生殖器官', '交配', '约炮');
     $contentStr = trim(str_replace($namesArray, '**', $contentStr));
     return array($contentStr, $ctype);
 }
Beispiel #2
0
 public function responseMsg($fromusername)
 {
     //get post data, May be due to the different environments
     $postStr = d_getpoststr($fromusername);
     if (strlen($postStr) == 0) {
         return '';
     }
     //extract post data
     if (!empty($postStr)) {
         $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
         $fromUsername = $postObj->FromUserName;
         $toUsername = $postObj->ToUserName;
         $getMsgType = $postObj->MsgType;
         $textTpl = "<xml>\n\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t</xml>";
         $imageTpl = "<xml>\n\t\t\t\t\t\t <ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t <FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t <CreateTime>%s</CreateTime>\n\t\t\t\t\t\t <MsgType><![CDATA[news]]></MsgType>\n\t\t\t\t\t\t <ArticleCount>1</ArticleCount>\n\t\t\t\t\t\t <Articles>\n\t\t\t\t\t\t <item>\n\t\t\t\t\t\t <Title><![CDATA[%s]]></Title> \n\t\t\t\t\t\t <Description><![CDATA[]]></Description>\n\t\t\t\t\t\t <PicUrl><![CDATA[%s]]></PicUrl>\n\t\t\t\t\t\t <Url><![CDATA[%s]]></Url>\n\t\t\t\t\t\t </item> \n\t\t\t\t\t\t </Articles>\n\t\t\t\t\t\t <FuncFlag>1</FuncFlag>\n\t\t\t\t\t\t </xml>";
         $msgType = 'text';
         if ($getMsgType == 'text') {
             $keyword = trim($postObj->Content);
             $webchat_textmsgObj = new webchat_textmsg();
             list($contentStr, $ctype) = $webchat_textmsgObj->dotext($keyword, $fromUsername);
         } else {
             if ($getMsgType == 'image') {
                 $msgType = 'text';
                 $contentStr = '亲,谢谢您分享图片~';
                 //database
                 d_inserttext($fromUsername, $PicUrl, $createTime, $contentStr, $time);
             } else {
                 if ($getMsgType == 'location') {
                     $wechat_weatherObj = new wechat_weather();
                     $contentStr = $wechat_weatherObj->getweatherbylocation($postObj->Label, $postObj->Location_X, $postObj->Location_Y);
                     $ctype = 'location';
                 } else {
                     if ($getMsgType == 'event') {
                         if ($postObj->Event == 'unsubscribe') {
                             $this->othermsg($fromUsername, $toUsername, $postStr, $postObj->CreateTime, $getMsgType);
                             d_setunsubscribe($fromUsername);
                             $ctype = 'unsubscribe';
                         } else {
                             if ($postObj->Event == 'subscribe') {
                                 $wechat_globleObj = new wechat_globle();
                                 $contentStr = $wechat_globleObj->welcome($fromUsername);
                                 $ctype = 'attention';
                             }
                         }
                     } else {
                         if (strstr($postStr, 'unsubscribe')) {
                             d_setunsubscribe($fromUsername);
                         } else {
                             $msgType = 'text';
                             $contentStr = '亲,主人还没教我听懂你说的话~55555 可以打字吗?';
                         }
                     }
                 }
             }
         }
         if (mb_strlen($contentStr, 'utf-8') > 500) {
             //set more
             $moretext = '(接上)' . mb_substr($contentStr, 500, mb_strlen($contentStr, 'utf-8') - 500, 'utf-8');
             $contentStr = mb_substr($contentStr, 0, 500, 'utf-8') . '【查看更多回复c】';
         }
         //回复消息
         $time = time();
         if ($ctype == 'music') {
             $resultStr = sprintf($imageTpl, $fromUsername, $toUsername, $time, $contentStr, "http://baiwanlu.com/music.jpg", "http://fm.baidu.com");
         } else {
             $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
         }
         echo $resultStr;
         //database
         if (!strstr($contentStr, 'Oops!')) {
             d_inserttext($fromUsername, $postStr, $postObj->CreateTime, $contentStr, $time, $ctype, $moretext);
         }
         exit;
     } else {
         echo '亲,你真的无话对我讲吗?';
     }
 }