tp3.2结合mysql实现微信自定义分享链接和图文
来源:互联网 发布:catti含金量 知乎 编辑:程序博客网 时间:2024/06/04 01:22
php代码
private function generateSign() { $noncestr = uniqid(); $timestamp = time(); $url = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; $ticket = $this->getJsapiTicket(); if ($ticket) { $str = 'jsapi_ticket=' . $ticket . '&noncestr=' . $noncestr . '×tamp=' . $timestamp . '&url=' . $url; $signature = sha1($str); $this->assign('noncestr', $noncestr); $this->assign('timestamp', $timestamp); $this->assign('signature', $signature); $this->assign('appId', 'xxxxxx'); $this->assign('link', $url); } } private function getJsapiTicket() { $map['id'] = 1; $map['update_time'] = array('GT', time() - 7200); $return = M('Wx_jsapi_ticket')->where($map)->find(); if ($return) { return $return['ticket']; } else { $token_info = $this->curlGetWxAccessToken(); $access_token = $token_info['access_token']; $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $access_token . '&type=jsapi'; $output = $this->curlHtml($url); $data = json_decode($output, true); if ($data['errcode'] == 0) { $condition['id'] = 1; $data['update_time'] = time(); $data['ticket'] = $data['ticket']; $up_result = M('Wx_jsapi_ticket')->where($condition)->save($data); if ($up_result !== false) { return $data['ticket']; } } } return false; } private function curlGetWxAccessToken() { $map['id'] = 1; $map['update_time'] = array('GT', time() - 7200); $return = M('Wx_token')->where($map)->find(); if ($return) { return $return; } else { $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxx&secret=xxxxxxxxx'; $output = $this->curlHtml($url); $data = json_decode($output, true); if ($data['errcode'] == 0) { $condition['id'] = 1; $data['update_time'] = time(); $data['access_token'] = $data['access_token']; $up_result = M('Wx_token')->where($condition)->save($data); if ($up_result !== false) { return $data; } } } return false; } private function curlHtml($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $output = curl_exec($ch); //释放curl句柄 curl_close($ch); return $output; }
html代码
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script><script>wx.config({ debug: false, appId: '<{$appId}>', // 必填,公众号的唯一标识 timestamp: <{$timestamp}>, // 必填,生成签名的时间戳 nonceStr: '<{$noncestr}>', // 必填,生成签名的随机串 signature: '<{$signature}>',// 必填,签名,见附录1 jsApiList: ['onMenuShareTimeline'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2});wx.ready(function () { // 分享到朋友圈 wx.onMenuShareTimeline({ title: '<{$data.title}>', // 名 link: '<{$link}>', // 地址 imgUrl: '<{$data.img}>', // 分享的图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } });});</script>
阅读全文
0 0
- tp3.2结合mysql实现微信自定义分享链接和图文
- 微信自定义分享链接和图文
- 微信自定义分享链接和图文
- 微信自定义分享链接
- 微信分享朋友圈分享代码自定义标题、说明、图标和分享链接
- 微信JS-SDK自定义分享链接
- 微信分享朋友圈自定义标题链接
- tp3.5 微信公众号群发图文消息
- jssdk实现自定义分享到微信好友和微信朋友圈
- PHP实现 微信--分享朋友链接
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
- PHP+MySQL微信通过jsapi分享到朋友圈等平台,实现设置图片、链接。
- 微信分享自定义内容实现
- 将企业协作与微信结合,明道打通微信实现从微信到明道的消息分享,目前已支持文字、图片以及链接
- 微信自定义分享
- 微信自定义分享
- 微信自定义分享
- beaglebone 设置时区 设置时间
- 怎样通过SQL SERVER 2012构建always on高性能的数据库集群
- NOIP2017_DAY2
- 计划2---灵活粘贴板
- 网络管理软件在高校网络中的应用
- tp3.2结合mysql实现微信自定义分享链接和图文
- Node.js是什么?
- Kotlin学习笔记--继承、接口、代理、委托、单例
- nginx新手指南
- [Leetcode] 454. 4Sum II 解题报告
- 周志华《Machine Learning》学习笔记(16)--概率图模型
- C++ 变量类型
- 通过Ajax方式上传文件,使用FormData进行Ajax请求
- 二叉搜索树的原理和实现