上一节课我们可以看得到了,那么现在我们就开始写回复页面了,
reply_view.php代码如下,
<?php $id = $_GET[‘id‘]; if(!empty($id)){ $connect = mysql_connect(‘localhost‘,‘root‘,‘root‘) or die(‘数据库链接失败‘); mysql_select_db(‘wxdb‘,$connect); mysql_query(‘set names utf8‘); $sql = "select * from zx_info where id=‘{$id}‘"; $res= mysql_query($sql,$connect); $row = mysql_fetch_assoc($res); }else{ exit; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>公众平台营销咨询系统</title> <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <link href="./jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"> <script src="./jquery-1.6.4.min.js" type="text/javascript"></script> <script src="./jquery.mobile-1.0.min.js" type="text/javascript"></script> </head> <body> <div data-role="page" id="page3"> <div data-role="header"> <h1>公众平台营销咨询系统</h1> <a href="#" data-role="button" data-icon="arrow-l" data-rel="back">点击返回</a> </div> <div data-role="content"> <ul data-role="listview"> <li> <?php echo $row[‘zx_info‘]; ?> </li> </ul> <form action="/reply.php?id=<?php echo $id ?>" method="post" > <div data-role="fieldcontain"> <label for="textarea">请输入回复内容:</label> <textarea cols="30" rows="10" name="textarea" id="textarea"></textarea> </div> <div class="ui-grid-a"> <div class="ui-block-a"> <button type="submit" data-role="button" >点击回复</button> </div> <div class="ui-block-b"> <button type="reset" data-role="button">取消回复</button> </div> </div> </form> </div> </div> </body> </html>
这里如果回复了那么表单将会发送数据到reply.php进行处理,reply.php代码如下所示:
<?php //获取token require ‘get_token.php‘; //这里调用common.php里面的封装好的curl函数 require "common.php"; //我们将后台管理员的回复推送给微信客户端 $id = $_GET[‘id‘]; $contentStr = $_POST[‘textarea‘]; //通过id查询到对应的openid $connect = mysql_connect(‘localhost‘,‘root‘,‘root‘) or die(‘数据库连接失败‘); mysql_select_db(‘wxdb‘,$connect); mysql_query(‘set names utf8‘); $sql = "select openid from zx_info where id=‘{$id}‘"; $res = mysql_query($sql,$connect); $row = mysql_fetch_assoc($res); $fromUsername = $row[‘openid‘]; //下一步我们就将$contentStr回复给用户 //对发送的内容进行urlencode编码,防止中文乱码 $contentStr = urlencode($contentStr); //到时候我们我发送的内容我们放到一个数组里面去了 $content_arr = array(‘content‘=>"{$contentStr}"); //这里的意思是将来我要发送消息给这个用户 $reply_arr = array(‘touser‘=>"{$fromUsername}",‘msgtype‘=>‘text‘,‘text‘=>$content_arr); //下一步就是将编码转成规定的json格式 $post = json_encode($reply_arr); //url解码,如果不解码他将会发来一段二进制代码 $post = urldecode($post); $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}"; http_request($url,$post); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>公众平台营销咨询系统</title> <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <link href="./jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"> <script src="./jquery-1.6.4.min.js" type="text/javascript"></script> <script src="./jquery.mobile-1.0.min.js" type="text/javascript"></script> </head> <body> <div data-role="page" id="page3"> <div data-role="header"> <h1>手机回复页面</h1> <a href="./show_info.php" data-role="button" data-icon="arrow-l" data-rel="back">点击返回</a> </div> <div data-role="content"> 恭喜您,已回复成功! </div> </div> </body> </html>
如果回见到已回复成功,那么恭喜您,您已经成功的回复了。
时间: 2024-10-14 02:43:09