|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
刚开始因为习惯于ASP格式的写法,总是在这些方面出现问题,自己还总是找不到问题所在,这就提醒了自己,在写代码的时候一定要认真,不能粗心地老是少个“;”或者字母大小写不分,要不然很可能找半天都找不到错误。一页代码完成微信基础复兴和点击事务功效,部署上往sae大概bae,妥妥的基础收费的服务器
不懂代码都基础每一个人都能够做本人的微信公家号了- valid();}else{//复兴动静$wechatObj->responseMsg();}classwechatCallbackapiTest{publicfunctionvalid(){$echoStr=$_GET["echostr"];if($this->checkSignature()){echo$echoStr;exit;}}privatefunctioncheckSignature(){$signature=$_GET["signature"];$timestamp=$_GET["timestamp"];$nonce=$_GET["nonce"];$token=TOKEN;$tmpArr=array($token,$timestamp,$nonce);sort($tmpArr);$tmpStr=implode($tmpArr);$tmpStr=sha1($tmpStr);if($tmpStr==$signature){returntrue;}else{returnfalse;}}//复兴动静publicfunctionresponseMsg(){$postStr=$GLOBALS["HTTP_RAW_POST_DATA"];if(!empty($postStr)){$postObj=simplexml_load_string($postStr,SimpleXMLElement,LIBXML_NOCDATA);$RX_TYPE=trim($postObj->MsgType);switch($RX_TYPE){case"text":$resultStr=$this->receiveText($postObj);break;case"image":$resultStr=$this->receiveImage($postObj);break;case"location":$resultStr=$this->receiveLocation($postObj);break;case"voice":$resultStr=$this->receiveVoice($postObj);break;case"video":$resultStr=$this->receiveVideo($postObj);break;case"link":$resultStr=$this->receiveLink($postObj);break;case"event":$resultStr=$this->receiveEvent($postObj);break;default:$resultStr="unknowmsgtype:".$RX_TYPE;break;}echo$resultStr;}else{echo"";exit;}}//吸收文本动静privatefunctionreceiveText($object){$keyword=trim($object->Content);$url="http://api100.duapp.com/movie/?appkey=DIY_miaomiao&name=".$keyword;$output=file_get_contents($url,$keyword);$contentStr=json_decode($output,true);if(is_array($contentStr)){$resultStr=$this->transmitNews($object,$contentStr);}else{$resultStr=$this->transmitText($object,$contentStr);}return$resultStr;}//吸收事务,存眷等privatefunctionreceiveEvent($object){$contentStr="";switch($object->Event){case"subscribe":$contentStr="你存眷了我";//存眷后复兴内容break;case"unsubscribe":$contentStr="";break;case"CLICK":$contentStr=$this->receiveClick($object);//点击事务break;default:$contentStr="receiveanewevent:".$object->Event;break;}return$contentStr;}//吸收图片privatefunctionreceiveImage($object){$contentStr="你发送的是图片,地点为:".$object->PicUrl;$resultStr=$this->transmitText($object,$contentStr);return$resultStr;}//吸收语音privatefunctionreceiveVoice($object){$contentStr="你发送的是语音,媒体ID为:".$object->MediaId;$resultStr=$this->transmitText($object,$contentStr);return$resultStr;}//吸收视频privatefunctionreceiveVideo($object){$contentStr="你发送的是视频,媒体ID为:".$object->MediaId;$resultStr=$this->transmitText($object,$contentStr);return$resultStr;}//地位动静privatefunctionreceiveLocation($object){$contentStr="你发送的是地位,纬度为:".$object->Location_X.";经度为:".$object->Location_Y.";缩放级别为:".$object->Scale.";地位为:".$object->Label;$resultStr=$this->transmitText($object,$contentStr);return$resultStr;}//链接动静privatefunctionreceiveLink($object){$contentStr="你发送的是链接,题目为:".$object->Title.";内容为:".$object->Description.";链接地点为:".$object->Url;$resultStr=$this->transmitText($object,$contentStr);return$resultStr;}
复制代码 //点击菜单动静privatefunctionreceiveClick($object){switch($object->EventKey){case"1":$contentStr="猫咪酱本性DIY打扮,我们专业定制本性【班服,情侣装,亲子装等,有是非T恤,卫衣,是非裤】来图印制便可,给你温馨心爱的TA,有事可间接留言微信";break;case"2":$contentStr="你点击了菜单:".$object->EventKey;break;case"3":$contentStr="是傻逼";break;default:$contentStr="你点击了菜单:".$object->EventKey;break;}//两种复兴if(is_array($contentStr)){$resultStr=$this->transmitNews($object,$contentStr);}else{$resultStr=$this->transmitText($object,$contentStr);}return$resultStr;}//复兴文本动静privatefunctiontransmitText($object,$content){$textTpl="%s";$resultStr=sprintf($textTpl,$object->FromUserName,$object->ToUserName,time(),$content);return$resultStr;}
//复兴图文privatefunctiontransmitNews($object,$arr_item){if(!is_array($arr_item))return;
$itemTpl="";$item_str="";foreach($arr_itemas$item)$item_str.=sprintf($itemTpl,$item[Title],$item[Description],$item[PicUrl],$item[Url]);
$newsTpl="%s%s$item_str";
$resultStr=sprintf($newsTpl,$object->FromUserName,$object->ToUserName,time(),count($arr_item));return$resultStr;}//音乐动静privatefunctiontransmitMusic($object,$musicArray,$flag=0){$itemTpl="";
$item_str=sprintf($itemTpl,$musicArray[Title],$musicArray[Description],$musicArray[MusicUrl],$musicArray[HQMusicUrl]);
$textTpl="%s$item_str%d";
$resultStr=sprintf($textTpl,$object->FromUserName,$object->ToUserName,time(),$flag);return$resultStr;}}?>
熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作完整的网页,对元素属性达到熟悉程度 |
|