这里做个知识总结分享下经验,望一起学习。。。。。
感觉后面写个系列的最好了 。。。。
企业需求:
给指定企业用户http://www.php.cn/php/php-s发送消息:如考勤信息、 企业通知、个人信息推送等等,
/// /// ///public static string GetPage(string posturl, string postData) { Stream outstream = null; Stream instream = null; StreamReader sr = null; HttpWebResponse response = null; HttpWebRequest request = null; Encoding encoding = Encoding.UTF8; byte[] data = encoding.GetBytes(postData); // 准备请求... try { // 设置参数 request = WebRequest.Create(posturl) as HttpWebRequest; CookieContainer cookieContainer = new CookieContainer(); request.CookieContainer = cookieContainer; request.AllowAutoRedirect = true; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; outstream = request.GetRequestStream(); outstream.Write(data, 0, data.Length); outstream.Close(); //发送请求并获取相应回应数据 response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求 instream = response.GetResponseStream(); sr = new StreamReader(instream, encoding); //返回结果网页(html)代码 string content = sr.ReadToEnd(); string err = string.Empty; return content; } catch (Exception ex) { string err = ex.Message; Como.LogUtil.WriteException("Tools GetPage 异常为:"+err.ToString()); return string.Empty; } }
参数引用详解:
1.Como.GetAccessToken.GetAccess_token() //获取 Access_token
2.GetPage //返回页面请求信息 结果
以上为基础发送关键代码:
以下为:成功后的实例图:
以上就是微信开发回复用户消息的代码实例分享的详细内容,更多请关注php中文网其它相关文章!