Authored by 2586703@qq.com

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohood into develop

... ... @@ -192,6 +192,7 @@ EOT;
public function detailAction()
{
$id = intval($this->_request->id);
$link = SITE_MAIN.url('news/detail', array('id' => $id));
$news = array();
if (empty($id))
{
... ... @@ -214,7 +215,7 @@ EOT;
$news = array($temp['id'] => $temp);
}
$news = array_slice(array_filter($news + $temp2), 0, 3);
$this->_view['wechat'] = Lib_Wechat_JSSDK::getSignPackage();
$this->_view['wechat'] = Lib_Wechat_JSSDK::getSignPackage($link);
}
$info['title'] = strip_tags($info['title']);
$info['pics'] = array_filter(explode('|', $info['pics']));
... ...
... ... @@ -3,7 +3,7 @@ class Lib_Wechat_JSSDK {
public static $appId = YOHO_WECHAT_APPID;
public static $appSecret = YOHO_WECHAT_APPSECRET;
public static function getSignPackage()
public static function getSignPackage($url = '')
{
$jsapiTicket = self::getJsApiTicket();
... ... @@ -11,7 +11,6 @@ class Lib_Wechat_JSSDK {
/* $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; */
// 确保你获取用来签名的url是动态获取的,动态页面可参见实例代码中php的实现方式。如果是html的静态页面在前端通过ajax将url传到后台签名,前端需要用js获取当前页面除去'#'hash部分的链接(可用location.href.split('#')[0]获取),因为页面一旦分享,微信客户端会在你的链接末尾加入其它参数,如果不是动态获取当前链接,将导致分享后的页面签名失败。
$url = '';
$timestamp = time();
$nonceStr = self::createNonceStr();
... ...
... ... @@ -44,6 +44,7 @@
</div>
<div class="overlay"></div>
</div>
<script type="text/javascript" charset="utf-8" src="http://staticzine.myoho.net/download/jquery.min.js?v=20150429"></script>
<script type="text/javascript" charset="utf-8" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<?php $this->_js('index.js', array(
SITE_JS . '/lib/seajs.js'
... ...
... ... @@ -82,46 +82,73 @@
<?php $this->_endblock();?>
<?php $this->_block('js');?>
<script type="text/javascript">
var wechatAppId = $(".share").attr("wechatAppId"),
wechatTimestamp = $(".share").attr("wechatTimestamp"),
wechatNonceStr = $(".share").attr("wechatNonceStr"),
wechatSignature = $(".share").attr("wechatSignature");
wx.config({
debug: true,
appId: wechatAppId,
timestamp: wechatTimestamp,
nonceStr: wechatNonceStr,
signature: wechatSignature,
jsApiList: ['checkJsApi','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ',
'onMenuShareWeibo','hideMenuItems','showMenuItems','hideAllNonBaseMenuItem','showAllNonBaseMenuItem',
'translateVoice','startRecord','stopRecord','onRecordEnd','playVoice','pauseVoice','stopVoice',
'uploadVoice','downloadVoice','chooseImage','previewImage','uploadImage','downloadImage',
'getNetworkType','openLocation','getLocation','hideOptionMenu','showOptionMenu','closeWindow',
'scanQRCode','chooseWXPay','openProductSpecificView','addCard','chooseCard','openCard'
]
});
wx.ready(function () {
wx.onMenuShareAppMessage({
title: '互联网之子',
desc: '在长大的过程中,我才慢慢发现,我身边的所有事,别人跟我说的所有事,那些所谓本来如此,注定如此的事,它们其实没有非得如此,事情是可以改变的。更重要的是,有些事既然错了,那就该做出改变。',
link: 'http://movie.douban.com/subject/25785114/',
imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg',
trigger: function (res) {
// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
alert('用户点击发送给朋友');
},
success: function (res) {
alert('已分享');
},
cancel: function (res) {
alert('已取消');
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
alert('aaa');
});
wx.error(function (res) {
alert(res.errMsg);
});
seajs.use(['jquery', 'mobile'],function($, mobile) {
mobile.detail();
var shareUrl = $(".share").attr("data-link"),
shareCover = $(".share").attr("cover-url"),
detailTitle = $('.detail-title').find('.title'),
detailSubtitle = $('.detail-title').find('.subtitle'),
wechatAppId = $(".share").attr("wechatAppId"),
wechatTimestamp = $(".share").attr("wechatTimestamp"),
wechatNonceStr = $(".share").attr("wechatNonceStr"),
wechatSignature = $(".share").attr("wechatSignature");
wx.config({
debug: false,
appId: wechatAppId,
timestamp: wechatTimestamp,
nonceStr: wechatNonceStr,
signature: wechatSignature,
jsApiList: ['checkJsApi','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ',
'onMenuShareWeibo','hideMenuItems','showMenuItems','hideAllNonBaseMenuItem','showAllNonBaseMenuItem',
'translateVoice','startRecord','stopRecord','onRecordEnd','playVoice','pauseVoice','stopVoice',
'uploadVoice','downloadVoice','chooseImage','previewImage','uploadImage','downloadImage',
'getNetworkType','openLocation','getLocation','hideOptionMenu','showOptionMenu','closeWindow',
'scanQRCode','chooseWXPay','openProductSpecificView','addCard','chooseCard','openCard'
]
});
wx.ready(function () {
var shareData = {
title: detailTitle,
desc: '123123',
imgUrl: shareCover,
link: shareUrl
};
// 2.1 “分享给朋友”
wx.onMenuShareAppMessage(shareData);
// 2.2 “分享到朋友圈”
wx.onMenuShareTimeline(shareData);
// 2.3 “分享到QQ”
wx.onMenuShareQQ(shareData);
// 2.4 “分享到微博”
wx.onMenuShareWeibo(shareData);
});
var shareData = {
title: $('.detail-title').find('.title'),
desc: '123123',
imgUrl: $(".share").attr("cover-url"),
link: $(".share").attr("data-link"),
success: function () // 用户确认分享后执行的回调函数
{
alert("OK");
},
cancel: function () { // 用户取消分享后执行的回调函数
alert("fail");
}
};
// 2.1 “分享给朋友”
// wx.onMenuShareAppMessage(shareData);
// 2.2 “分享到朋友圈”
// wx.onMenuShareTimeline(shareData);
// 2.3 “分享到QQ”
// wx.onMenuShareQQ(shareData);
// 2.4 “分享到微博”
// wx.onMenuShareWeibo(shareData);
});
</script>
<?php $this->_endblock();?>
... ...