Authored by whb

测试微信接口

... ... @@ -214,7 +214,7 @@ EOT;
$news = array($temp['id'] => $temp);
}
$news = array_slice(array_filter($news + $temp2), 0, 3);
$this->_view['wechat'] = array();//Lib_Wechat_JSSDK::getSignPackage();
$this->_view['wechat'] = Lib_Wechat_JSSDK::getSignPackage();
}
$info['title'] = strip_tags($info['title']);
$info['pics'] = array_filter(explode('|', $info['pics']));
... ...
... ... @@ -11,7 +11,7 @@ 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 = $_REQUEST['pageurl'];
$url = '';
$timestamp = time();
$nonceStr = self::createNonceStr();
... ... @@ -70,7 +70,7 @@ class Lib_Wechat_JSSDK {
public static function getAccessToken()
{
$http_url = 'https://api.weixin.qq.com/cgi-bin/token?';
$params = array('appid'=> self::$appId,'secret' => self::$appSecret,'grant_type'=>'client_credential');
$params = array('appid'=> YOHO_WECHAT_APPID,'secret' => YOHO_WECHAT_APPSECRET,'grant_type'=>'client_credential');
$access_token = Lib_Utils_Cache_Data::get("WEICHAT_ACCESSTOKEN");
if(empty( $access_token ))
{
... ...
... ... @@ -44,6 +44,7 @@
</div>
<div class="overlay"></div>
</div>
<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'
));?>
... ...
... ... @@ -70,7 +70,9 @@
<div id="share" class="share" cover-url="<?php
$thumb = empty($this->view->info['client_thumb']) ? $this->view->info['thumb'] : $this->view->info['client_thumb'];
echo Lib_Images::getImageUrl($thumb, 'source','fragmentimg');?>"
data-link="<?php echo SITE_MAIN.'/news/detail/id/'.$this->view->info['id'];?>" wechatAppId="" wechatTimestamp="" wechatNonceStr="" wechatSignature="">
data-link="<?php echo SITE_MAIN.'/news/detail/id/'.$this->view->info['id'];?>" wechatAppId="<?php echo $this->view->wechat['appId'];?>"
wechatTimestamp="<?php echo $this->view->wechat['timestamp'];?>" wechatNonceStr="<?php echo $this->view->wechat['nonceStr'];?>"
wechatSignature="<?php echo $this->view->wechat['signature'];?>">
<ul class="clearfix">
<li class="yohoo-share-button-sina"><a href="javascript:;"></a></li>
<li class="yohoo-share-button-qq"><a href="javascript:;"></a></li>
... ... @@ -79,37 +81,7 @@
</div>
<?php $this->_endblock();?>
<?php $this->_block('js');?>
<script type="text/javascript" charset="utf-8" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
var shareData = {
title: '',
desc: '',
imgUrl: '',
link: '',
};
// wx.config({
// debug: false,
// appId: '',
// timestamp: '',
// nonceStr: '',
// signature: '',
// 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'
// ]
// });
// // 2.1 “分享给朋友”
// wx.onMenuShareAppMessage(shareData);
// // 2.2 “分享到朋友圈”
// wx.onMenuShareTimeline(shareData);
// // 2.3 “分享到QQ”
// wx.onMenuShareQQ(shareData);
// // 2.4 “分享到微博”
// wx.onMenuShareWeibo(shareData);
seajs.use(['jquery', 'mobile'],function($, mobile) {
mobile.detail();
var shareUrl = $(".share").attr("data-link"),
... ... @@ -120,6 +92,36 @@
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: '',
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);
});
});
</script>
<?php $this->_endblock();?>
... ...