好久没写技术博客了,最近一直在忙武大微淘的项目,团队中我的角色最主要是CTO,整个项目的网站、APP、微信基本上都是我一个人在弄,每天有写不完的代码,调不完的样式,天天盯着电脑,妈蛋。虽然说武大微淘系列产品采用的是开源系统二次开发而成,但是自己要做的事情还是有很多。首先是样式方面,下载下来的那个开源系统是一个订餐管理系统,美工设计方面就很差,不是一个正规的电子商务网站的那种样子,而我对武大微淘的定位就是一个电子商务平台,主要是O2O与B2C的结合,所以在样式方面必然要调成一个电子商务网站的模样,于是花了大把大把的时间调css样式,最终调成现在这个样子。虽然说算不上高大上,单勉勉强强还能看。手机网站的美工设计我个人觉得还很不满意,所以接下来还要花很多的时间去做手机网站的美工。再者对于此开源系统的功能性,也有很多需要修改的地方,比如根据店铺类型显示不同的店铺就需要自己在数据库中添加字段然后重写数据库查询语句,再一个就是提交订单方面用到的ajax保存数据就经常出现bug。总而言之,这个开源系统完美性差,可塑性强,为了将其做成我想要的武大微淘,花了不少时间。
今天这篇博客的重点还是说一下武大微淘微信版的实现原理,感兴趣的朋友可以关注武大微淘,根据回复不同关键词获取不同的信息,然后再根据回复的信息看一下实现此功能的源代码。本次微信开发用的是Thinkphp框架,毕竟我是寒假才看的Thinkphp教程,而且只看了一小部分,所以很多功能函数都是边百度边使用的,所幸的是我最终还是用此框架将微信版武大微淘的全部功能给写出来了。默默的给自己赞一个,同时送给热爱计算机技术,想在IT编程这条路上有所进步的朋友一句话:不要等到什么都学会了才去做开发,只有边学习边实践才能有所进步。话不多说,直接上代码。
武大微淘微信版是thinkphp和微信开发结合的很好尝试,欢迎广大IT爱好者提出指点意见。
1、用户第一次关注“武大微淘”时回复欢迎信息。
1 2 3 4 5 6 7 8 9 | //事件消息 if($form_MsgType=="event"){ $form_Event=$postObj->Event; //用户订阅事件 if($form_Event=="subscribe"){ //回复欢迎消息 $this->responseWelcome($fromUsername,$toUsername,$keyword,$time,$textTpl); } } |
1 2 3 4 5 6 7 | //自定义函数,响应用户关注消息 public function responseWelcome($fromUsername,$toUsername,$keyword,$time,$textTpl){ $msgType = "text"; $contentStr = "欢迎关注【<a href='http://weitao.bestwhu.com/'>武大微淘</a>】\n我们的口号是:\n让极速成为一种态度!\n绑定个人信息后,只需回复商品编号如【m3】即可在微信中下单购买。你也可以在电脑浏览器地址栏输入网址:\nweitao.bestwhu.com\n查看武大微淘平台上的店铺、商品信息。\n回复任意内容开始你的极速购物之旅\n查看操作说明请回复【?】"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } |
2、用户回复任意内容响应默认消息。
1 2 | //默认回复消息 $this->responseDefault($fromUsername,$toUsername,$keyword,$time,$textTpl); |
1 2 3 4 5 6 7 8 9 10 11 12 | public function responseDefault($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $msgType = "text"; $contentStr = "【<a href='http://weitao.bestwhu.com?open_id=".$fromUsername."'>武大微淘</a>,让极速成为一种态度!】\n回复【?】查看操作说明\n回复以下数字选择你所需的商品:\n【1】零食\n【2】水果\n【3】盒饭\n【4】夜宵\n回复以下数字选择你所需的服务:\n【5】极速购物\n【6】听听歌\n【7】查成绩\n【8】关于我们\n【9】留言咨询\n"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } |
3、用户回复【1、2、3、4】时查看对应类型的店铺列表。
1 2 3 4 5 | //用户发送消息为“1”“2”“3”“4” if($keyword=="1" || $keyword=="2" || $keyword=="3" || $keyword=="4" ){ //查看店铺类型等于用户回复数字的店铺列表 $this->responseListShop($fromUsername,$toUsername,$keyword,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | public function responseListShop($fromUsername,$toUsername,$keyword,$time,$textTpl){ if($keyword) { switch($keyword) { case 1: $areaName="零食"; $coverPic="http://ipic-ipic.stor.sinaapp.com/original/eebe900c940d26da5bb904d4bd60b258.jpg"; break; case 2: $areaName="水果"; $coverPic="http://ipic-ipic.stor.sinaapp.com/original/7ac4dfeed0159f41dfa1d5357561d95e.jpg"; break; case 3: $areaName="盒饭"; $coverPic="http://ipic-ipic.stor.sinaapp.com/original/afb37fc60f41ca3a4bcd81acf1297d58.jpg"; break; case 4: $areaName="夜宵"; $coverPic="http://ipic-ipic.stor.sinaapp.com/original/3624bbe8a9d814d93c94883d0999b0cd.jpg"; break; } //实例化店铺“meal_shop”信息表模型 $Data1 = M('meal_shop'); //获取记录集 $test=$keyword; $condition["shop_sms_tel"]=array("eq",$test); $condition["shop_extend"]=array("neq","); $data1 = $Data1->where($condition)->select(); //获取查询记录数 $count=$Data1->where($condition)->count(); //图文消息返回总数 $showMenu=$count+2; $resultStr="<xml>\n <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>\n <FromUserName><![CDATA[".$toUsername."]]></FromUserName>\n <CreateTime>".$time."</CreateTime>\n <MsgType><![CDATA[news]]></MsgType>\n <ArticleCount>".$showMenu."</ArticleCount>\n <Articles>\n"; //添加封面图文消息 $resultStr.="<item>\n <Title><![CDATA[共有".$count."家【".$areaName."】店为你服务]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[".$coverPic."]]></PicUrl>\n <Url><![CDATA[http://weitao.bestwhu.com/]]></Url>\n </item>\n"; if($count>0){ $resultStr.="<item>\n <Title><![CDATA[回复【店铺编号】查看本店商品!\n如【s1】]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[]]></PicUrl>\n <Url><![CDATA[]]></Url>\n </item>\n"; }else{ $resultStr.="<item>\n <Title><![CDATA[该类型店铺即将上线,敬请期待!\n查看操作说明请回复【?】]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[]]></PicUrl>\n <Url><![CDATA[]]></Url>\n </item>\n"; } //回复店铺信息 foreach($data1 as $item){ if(empty($item[shop_pic])){ $shop_pic="http://ipic-ipic.stor.sinaapp.com/original/919c5930cce562bfc213f372adcf49b3.jpg"; }else{ $shop_pic="http://weitao.bestwhu.com/".$item[shop_pic]; } $resultStr.="<item>\n <Title><![CDATA[【s".$item[shop_id]."】".$item[shop_name]."]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[".$shop_pic."]]></PicUrl>\n <Url><![CDATA[http://weitao.bestwhu.com/?app_act=shop&id=".$item[shop_id]."]]></Url>\n </item>\n"; } $resultStr.="</Articles>\n <FuncFlag>0</FuncFlag>\n </xml>"; echo $resultStr; exit; }else{ $msgType = "text"; $contentStr = "输入不正确"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } } |
4、用户回复店铺编号如【s3】时查看对应的商品类型或商品列表。
1 2 3 4 5 | //用户发送消息以“s”开头时 if($keyword3=="s"){ //根据“s”后面的店铺编号查看店铺商品类型 $this->responseMealType($fromUsername,$toUsername,$keyword4,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | public function responseMealType($fromUsername,$toUsername,$keyword,$time,$textTpl){ //实例化店铺“meal_shop”信息表模型 $Data1 = M('meal_shop'); //根据用户输入条件查询对应店铺 $condition1['shop_id']=$keyword; $data1 = $Data1->where($condition1)->find(); //实例化商品“meal_menu”信息表模型 $Data2= M('meal_menu_group'); //联合查询 $condition2['group_shop_id']=$data1['shop_id']; $data2=$Data2->where($condition2)->select(); //获取查询记录数 $count=$Data2->where($condition2)->count(); //图文消息返回总数 if($count==0){ $this->responseMealMenu2($fromUsername,$toUsername,$keyword,$time,$textTpl); } $showMenu=$count+2; if($showMenu>10){ $showMenu=10; } $resultStr="<xml>\n <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>\n <FromUserName><![CDATA[".$toUsername."]]></FromUserName>\n <CreateTime>".$time."</CreateTime>\n <MsgType><![CDATA[news]]></MsgType>\n <ArticleCount>".$showMenu."</ArticleCount>\n <Articles>\n"; //添加封面图文消息 if(empty($data1[shop_pic])){ $shop_pic="http://weitao.bestwhu.com/webcss/default/images/logo.png"; } else{ $shop_pic="http://weitao.bestwhu.com/".$data1[shop_pic]; } $resultStr.="<item>\n <Title><![CDATA[【".$data1[shop_name]."】共有商品种类:".$count."]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[".$shop_pic."]]></PicUrl>\n <Url><![CDATA[http://weitao.bestwhu.com/?app_act=shop&id=".$data1[shop_id]."]]></Url>\n </item>\n"; $resultStr.="<item>\n <Title><![CDATA[回复【类型编号】查看商品\n如【t21】]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[]]></PicUrl>\n <Url><![CDATA[]]></Url>\n </item>\n"; //回复商品信息 foreach($data2 as $item){ $resultStr.="<item>\n <Title><![CDATA[【t".$item[group_id]."】".$item[group_name]."]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[]]></PicUrl>\n <Url><![CDATA[http://weitao.bestwhu.com/?app_act=shop&id=".$data1[shop_id]."]]]></Url>\n </item>\n"; } $resultStr.="</Articles>\n <FuncFlag>0</FuncFlag>\n </xml>"; echo $resultStr; exit; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | //实例化商品“meal_menu”信息表模型 $Data2= M('meal_menu'); //联合查询 $condition2['menu_group_id']=$keyword; $data2=$Data2->where($condition2)->select(); //获取查询记录数 $count=$Data2->where($condition2)->count(); $group_info=M('meal_menu_group'); $group_condition['group_id']=$keyword; $group_data=$group_info->where($group_condition)->find(); //图文消息返回总数 if($count==0){ $msgType="text"; $contentStr="你所查看的类型暂时没有商品!请查看其他类型。\n查看帮助请回复【8】"; $resultStr=sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } $showMenu=$count+1; if($showMenu>10){ $showMenu=10; } $resultStr="<xml>\n <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>\n <FromUserName><![CDATA[".$toUsername."]]></FromUserName>\n <CreateTime>".$time."</CreateTime>\n <MsgType><![CDATA[news]]></MsgType>\n <ArticleCount>".$showMenu."</ArticleCount>\n <Articles>\n"; //添加封面图文消息 $resultStr.="<item>\n <Title><![CDATA[]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[]]></PicUrl>\n <Url><![CDATA[]]></Url>\n </item>\n"; $resultStr.="<item>\n <Title><![CDATA[回复【商品编号,份数】可极速订购,\n默认份数为1,多种商品请用【&】隔开,\n如回复【m36】、【m14,3】、\n【m2,3&m4,4&m8】等均可下单]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[]]></PicUrl>\n <Url><![CDATA[]]></Url>\n </item>\n"; //回复商品信息 foreach($data2 as $item){ if(empty($item[menu_pic])){ $menu_pic="http://ipic-ipic.stor.sinaapp.com/original/e761d1e1753e7e2be1ee2106bcbce859.jpg"; }else{ $menu_pic="http://weitao.bestwhu.com/".$item[menu_pic]; } $resultStr.="<item>\n <Title><![CDATA[【m".$item[menu_id]."】".$item[menu_title]."(¥".$item[menu_price].")]]></Title> \n <Description><![CDATA[]]></Description>\n <PicUrl><![CDATA[".$menu_pic."]]></PicUrl>\n <Url><![CDATA[]]></Url>\n </item>\n"; } $resultStr.="</Articles>\n <FuncFlag>0</FuncFlag>\n </xml>"; echo $resultStr; exit; } |
5、用户回复商品编号开始下单时
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | //用户发送消息以“m”开头时 if($keyword3=="m" && !strstr($keyword,"&")){ //响应用户下订单请求 //判断用户是否绑定个人信息 $userState=$this->responseCheckUser($fromUsername,$toUsername,$keyword,$time,$textTpl); //如果用户已绑定个人信息 if($userState){ //将用户发送消息“m”后面的字符串以“,”分割 $order_array=explode(",",str_replace(",",",",$keyword4)); //分割后的字段数 if(empty($order_array[1])){ $order_array[1]=1; } $order_info=$order_array[0]."*".$order_array[1]; //快捷下订单 $this->responseQuickBuy($fromUsername,$toUsername,$order_info,$time,$textTpl); } } |
a.如果用户未绑定个人信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | //自定义函数,检测用户是否绑定帐号信息 public function responseCheckUser($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $myOrder=M('meal_info'); $condition['info_open_id']=".$fromUsername; $my_order=$myOrder->where($condition)->select(); $msgType = "text"; if($my_order){ return true; } else{ $contentStr ="你尚未绑定个人信息,为方便你的微信购物之旅,请回复:\n【bd+你的个人信息】\n进行绑定(注意用逗号隔开)。格式为:\n【bd姓名,学部,宿舍,电话】\n如:\n【bd刘德华,工学部,工5-501,15527516883】\n"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; return false; } }else{ echo "说点什么吧..."; } } |
b.如果用户绑定了个人信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | //自定义函数,处理订单 public function responseGetOrderInfo($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(strlen( $keyword )>0) { $keyword_array=explode("&",$keyword); $i=0; $order_ids_array=array(); $order_nums_array=array(); foreach($keyword_array as $item){ $item_1=$this->GBsubstr($item,0,1); $item_2=$this->GBsubstr($item,1); $order_array=explode(",",$item_2); if(empty($order_array[1])){ $order_array[1]=1; } for($j=0;$j<$order_array[1];$j++){ $order_ids_array[$i]=$order_array[0]."|"; } if(empty($order_array[1])){ $order_array[1]=1; } $order_nums_array[$i]=$order_array[1]; $i++; } $order_ids=substr(implode('',$order_ids_array),0,-1); $order_nums=implode("/",$order_nums_array); return $order_ids."*".$order_nums; }else{ $this->responseError($fromUsername,$toUsername,$keyword,$time,$textTpl); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | //自定义函数,响应用户在微信只输入【商品编号,购买份数】的情况下下单购买商品 public function responseQuickBuy($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $order_info=explode("*",$keyword); $order_ids_array=explode("|",$order_info[0]); $order_ids=$order_info[0]; $order_nums_array=explode("/",$order_info[1]); $total_price=0.0; $order_detail="; $i=0; foreach($order_ids_array as $order_item){ $menuInfo=M('meal_menu'); $condition['menu_id']=$order_item; $order_info=$menuInfo->where($condition)->find(); $total_price+=$order_info['menu_price']*intval($order_nums_array[$i]); $order_shop_id=$order_info['menu_shop_id']; $order_detail.=$order_info['menu_title']."=>¥".$order_info['menu_price']."x".$order_nums_array[$i]."\n"; $i++; } $userInfo=M('meal_info'); $condition2['info_open_id']=".$fromUsername; $user_info=$userInfo->where($condition2)->order("info_id desc")->find(); $userMsg=D('meal_order'); $data['order_open_id']=$user_info['info_open_id']; $data['order_area_id']="; $data['order_area_allid']="; $data['order_area']=$user_info['info_area']; $data['order_louhao1']=$user_info['info_louhao1']; $data['order_name']=$user_info['info_name']; $data['order_sex']="同学"; $data['order_mobile']=$user_info['info_mobile']; $data['order_arrive']="; $data['order_addtime']=time(); $data['order_time']=date('Y-m-d H:i:s',time()); $data['order_user_id']="; $data['order_ids']=$order_ids; $data['order_total']=$total_price; $data['order_total_pay']=$total_price; $data['order_number']=$order_shop_id.date("ymdHis"); $data['order_day']=date('Y-m-d',time()); $data['order_detail']="; $data['order_shop_id']=$order_shop_id; $data['order_pay_method']="afterpayment"; $buyDate=$userMsg->add($data); if($buyDate){ $contentStr = "你的订单已提交,商家确认后会尽快给你送货,本次订单的配送地址:".$order_info[0].$user_info['info_area'].$user_info['info_louhao1']."\n取消本订单请回复【qx".$data['order_number']."】\n查看本订单处理状态请回复【cx".$data['order_number']."】,回复【?】查看操作说明,感谢你的支持!\n你的订单详情:\n订单号:\n".$data['order_number']."\n商品列表:\n".$order_detail."\n应支付:¥".$data['order_total_pay']."; } else{ $contentStr = "提交订单失败!\n失败原因:你购买的商品不存在或者你的输入不符合给定格式。\n回复【?】查看操作说明!"; } $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } |
6、用户查看订单状态【cx订单号】
1 2 3 4 5 | //用户发送消息以“cx”开头时 if($keyword5=="cx" || $keyword5=="CX"){ //根据“cx”后面的订单号查询订单状态 $this->responseOrderState($fromUsername,$toUsername,$keyword6,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | //自定义函数,响应用户查看订单状态请求 public function responseOrderState($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $myOrder=M('meal_order'); $condition['order_number']=".$keyword; $my_order=$myOrder->where($condition)->find(); $myOrder2=M('meal_menu'); $condition2['menu_shop_id']=$my_order['order_shop_id']; $my_order2=$myOrder2->where($condition2)->find(); $myOrder3=M('meal_shop'); $condition3['shop_id']=$my_order2['menu_shop_id']; $my_order3=$myOrder3->where($condition3)->find(); $msgType = "text"; $contentStr = "你查看的订单详情:\n"; switch($my_order['order_state']){ case 0: $orderState="订单已提交..."; break; case 1: $orderState="商家送货中..."; break; case -4: $orderState="订单已取消..."; break; } $contentStr.="【下单时间】\n".$my_order['order_time']."\n【订单状态】\n".$orderState."\n【店铺名称】\n".$my_order3['shop_name']."\n【电话催单】\n".$my_order3['shop_tel']; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ $this->responseError($fromUsername,$toUsername,$keyword,$time,$textTpl); } } |
7、用户取消订单【qx订单号】
1 2 3 4 | if($keyword5=="qx" || $keyword5=="QX"){ //根据“cx”后面的订单号查询订单状态 $this->responseQuitOrder($fromUsername,$toUsername,$keyword6,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //自定义函数,取消订单 public function responseQuitOrder($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $myOrder=M('meal_order'); $condition['order_number']=".$keyword; $condition['order_open_id']=".$fromUsername; $my_order=$myOrder->where($condition)->delete(); if($my_order){ $contentStr="你的订单已取消,回复任意内容继续购物。"; } else{ $contentStr="订单取消失败,可能原因:\n1、这不是你的订单。\n2、此订单不存在。\n3、你的输入有误。"; } $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ $this->responseError($fromUsername,$toUsername,$keyword,$time,$textTpl); } } |
8、用户提交留言【#留言内容】
1 2 3 4 5 | //用户发送消息为“9” if($keyword=="9"){ //响应用户留言请求 $this->responseLeaveMessage($fromUsername,$toUsername,$keyword,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 | //自定义函数,响应留言咨询请求(9) public function responseLeaveMessage($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $msgType = "text"; $contentStr = "你有任何话想对我们说请直接在微信中回复\n【#你的留言内容】\n如:【#我发现了一个bug】"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } |
1 2 3 4 5 | //用户发送消息以“#”开头时 if($keyword3=="#"){ //将“#”后面的内容作为用户留言插入 $this->responseUserMsg($fromUsername,$toUsername,$keyword4,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //自定义函数,响应用户在微信直接提交的留言(#) public function responseUserMsg($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(strlen( $keyword )>0) { $userMsg=D('other_msg'); $data['msg_cont']=$keyword; $userMsg->add($data); $msgType = "text"; $contentStr = "你的留言已提交,感谢你的支持!\n查看操作说明请回复【?】"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ $this->responseError($fromUsername,$toUsername,$keyword,$time,$textTpl); } } |
9、用户极速购物【5】、听音乐【6】、查成绩【7】、查看帮助【8】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //用户发送消息“5” if($keyword=="5"){ //响应极速购物,向用户推荐商品套餐 $this->responseJiSu($fromUsername,$toUsername,$keyword,$time,$textTpl); } //用户发送消息为“music”或者“6”时 if($keyword=="music" || $keyword=="6"){ //回复音乐消息,每日一曲 // $this->responseMusic($fromUsername,$toUsername,$time,$musicTpl); //回复文本消息,点击链接跳转到音乐盒子 $this->responseDaylyMusic($fromUsername,$toUsername,$keyword,$time,$textTpl); } //用户发送消息为“7”时 if($keyword=="7"){ //响应用户查分请求 $this->responseChaFen($fromUsername,$toUsername,$keyword,$time,$textTpl); } //用户发送消息为"help"或者“8”时 if($keyword=="help" || $keyword=="8"){ //回复帮助消息 $this->responseHelp($fromUsername,$toUsername,$time); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | //极速购物 public function responseJiSu($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $msgType = "text"; // $contentStr = "<a href='http://prod.thinkful.cn/plan/fun/whuscore'>点此</a>开始查询你的成绩"; $contentStr = "回复【】里的内容可购买对应商品\n【m30】老坛酸菜泡面(桶装)(¥4)\n【m28】阿萨姆奶茶(¥4)\n【m7】熊字饼(¥2)\n【m9】奥利奥(¥5.5)\n【m13】酒鬼花生(¥3)\n【m10】豆腐干(¥2)\n【m21】恰恰香瓜子(¥5)\n【m24】乐吧薯片(¥2)"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } //自定义函数,响应查分请求(6) public function responseChaFen($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $msgType = "text"; // $contentStr = "<a href='http://prod.thinkful.cn/plan/fun/whuscore'>点此</a>开始查询你的成绩"; $contentStr = "<a href='http://prod.thinkful.cn/plan/fun/whuscore?frm=idoubi'>点此</a>开始查询你的成绩"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } //自定义函数,响应听听歌请求(7) public function responseDaylyMusic($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $msgType = "text"; $contentStr = "<a href='http://ztalk.sinaapp.com/audio.html'>点此</a>进入音乐盒子"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } //自定义函数,响应查看帮助请求(8) public function responseHelp($fromUsername,$toUsername,$time){ $resultStr="<xml>\n <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>\n <FromUserName><![CDATA[".$toUsername."]]></FromUserName>\n <CreateTime>".time()."</CreateTime>\n <MsgType><![CDATA[news]]></MsgType>\n <ArticleCount>1</ArticleCount>\n <Articles>\n <item>\n <Title><![CDATA[关于武大微淘与常见问题说明!]]></Title> \n <Description><![CDATA[详情请点击阅读全文]]></Description>\n <PicUrl><![CDATA[http://ipic-ipic.stor.sinaapp.com/original/7c13ed3f275509e04520cdb9c66b6922.png]]></PicUrl>\n <Url><![CDATA[http://mp.weixin.qq.com/s?__biz=MjM5ODA3Mjk1MA==&mid=200059733&idx=1&sn=8668091be9a7699983b6be96573163d3#rd]]></Url>\n </item>\n </Articles>\n <FuncFlag>0</FuncFlag>\n </xml>"; echo $resultStr; exit; } |
10、用户查看操作说明【?】
1 2 3 4 5 | //用户发送消息为“?” if($keyword=="?" || $keyword=="?"){ //响应用户查看操作说明 $this->responseBaseHelp($fromUsername,$toUsername,$keyword,$time,$textTpl); } |
1 2 3 4 5 6 7 8 9 10 11 12 | //自定义函数,响应用户查看操作说明(?) public function responseBaseHelp($fromUsername,$toUsername,$keyword,$time,$textTpl){ if(!empty( $keyword )) { $msgType = "text"; $contentStr = "回复【1】查看零食店\n回复【2】查看水果店\n回复【3】查看外卖店\n回复【4】查看夜宵店\n回复【店铺编号】\n如【s1】查看该店商品\n回复【商品类型编号】\n如【t1】查看该类型商品\n回复【商品编号】\n如【m3】可直接在微信中下单购买\n回复【5】查看热销商品\n回复【9】向我们反馈你在使用本平台遇到的问题\n武大微淘,让极速成为一种态度!感谢你的支持"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "说点什么吧..."; } } |