include (‘./Lib/COM/jssdk.php‘);
$jssdk = new JSSDK($tpl[‘appid‘], $tpl[‘appsecret‘]);
$signPackage = $jssdk -> GetSignPackage();
//在Action层实现jssdk初始化参数的获取,jssdk封装了api调用的细节
public function getSignPackage() {
$jsapiTicket = $this->getJsApiTicket();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER[‘HTTPS‘]) && $_SERVER[‘HTTPS‘] !== ‘off‘ || $_SERVER[‘SERVER_PORT‘] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this->createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array(
"appId" => $this->appId,
"nonceStr" => $nonceStr,
"timestamp" => $timestamp,
"url" => $url,
"signature" => $signature,
"rawString" => $string
);
return $signPackage;
}
//执行配置
wx.config({
debug: true, //开发时开启调试,可获得弹出错误提示信息
appId: ‘wx2e0bde3x3fa332b‘,
timestamp: ‘1437016703‘,
nonceStr: ‘x7GInQ2pQtzF7fxt‘,
signature: ‘ef80a58a197ede439e0beb2360ef378e2b4fb204‘,
jsApiList: [
‘onMenuShareTimeline‘,
‘onMenuShareTimeline‘
]
});
//在ready方法中执行
wx.ready(function() {
//定制朋友圈分享
wx.onMenuShareTimeline({
title: ‘{维尔特}--明星讲故事‘, // 分享标题
link: ‘http://www.baidu.com‘, // 分享链接
imgUrl: ‘http://my.emplog.com/uploads/u/uxzdcn1426737865/d/2/0/6/thumb_55a4749bdac1c.jpg‘, // 分享图标
success: function() {
//分享成功
},
cancel: function() {
//分享取消
}
});
//定制发送给朋友
wx.onMenuShareAppMessage({
title: ‘{维尔特}--明星讲故事‘, // 分享标题
desc: ‘{维尔特}--明星讲故事‘, // 分享描述
link: ‘http://www.baidu.com‘, // 分享链接
imgUrl: ‘http://my.emplog.com/uploads/u/uxzdcn1426737865/d/2/0/6/thumb_55a4749bdac1c.jpg‘, // 分享图标
type: ‘‘, // 分享类型,music、video或link,不填默认为link
dataUrl: ‘‘, // 如果type是music或video,则要提供数据链接,默认为空
success: function() {
},
cancel: function() {
}
});
wx.error(function(res) {
//alert(res.errMsg);
});
})
location / {
proxy_pass http://120.21.33.81:9031;
proxy_set_header Host $host;
}
原文:http://www.cnblogs.com/littleatp/p/4652596.html