如何实现微信关键字回复消息

这里只有后台代码

首先要从前台 表单获取 提交的数据 获取到以后 存到相应的数据库中 这里我写了两张表

一张是存关键字类型的  一张专门存放类型为text的内容表 有联系的字段是replyid

具体代码如下

	public function replyText(){

		$mpid = getIsUse();
		$data['content']=I('post.content');
		$model = M('replytext');
		$replyid=$model->add($data);
        $text['replyid']=$replyid;
        $text['mpid']=$mpid;
        $text['type']='text';
		$text['keyword']=I('post.keyword');
		//关键字
		$m=M('replyrule');
		$m->add($text);
		$this->ajaxReturn(array('msg'=>'成功添加'));
    
		
	}

写完后台 我使用的是lanewechat  这里相关代码如下

public static function text(&$request){
        $mpid=$_GET['id'];//这是获取配置成工那里的ID
        $where['mpid']=$mpid;
        $where['keyword']=$request['content'];//得到关键字 
        $data = M('replyrule')->where($where)->find();//根据关键字和id查询记录
        if($data){
            if($data['type']=='text'){
                $a=M('replytext')->find($data['replyid']);
                $content = $a['content'];
                return ResponsePassive::text($request['fromusername'], $request['tousername'], $content);
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值