作者 jinglong
1 个管道 的构建 通过 耗费 0 秒

调式微信分享

... ... @@ -522,7 +522,7 @@ class LoginController extends HomeBaseController
}
//获取微信分享配置信息
public function configShareWx($url=''){
public function wx_share($url=''){
$jsapiTicket = $this->getSignature();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
... ... @@ -541,7 +541,8 @@ class LoginController extends HomeBaseController
"signature" => $signature,
"rawString" => $string
];
$this->apiResponse(1, '成功',$data);
$this->assign('data',$data);
return $this->fetch();
}
//获取微信分享签名随机字符串
... ...
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>分享主题</h1>
</body>
</html>
<script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script>
<script src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
$(function () {
wx.config({
debug: true,
appId: '{$data.appId}',
timestamp: '{$data.timestamp}',
nonceStr: '{$data.nonceStr}',
signature: '{$data.signature}',
jsApiList: [
'updateAppMessageShareData',
]
});
wx.ready(function () { //需在用户可能点击分享按钮前就先调用
wx.updateAppMessageShareData({
title: '分享标题', // 分享标题
desc: '分享描述', // 分享描述
link: 'http://www.starplanet.cn/portal/enjoy/getEnjoyDetail?id=81', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: '', // 分享图标
success: function (e) {
// 设置成功
console.log(e);
}
})
});
});
</script>
... ...
... ... @@ -34,56 +34,3 @@
</li>
</ul>
</div>
<script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script>
<script src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
$(function () {
var appid = '';
var timestamp = '';
var nonceStr = '';
var signature = '';
$.ajax({
type: 'POST',
url: '/portal/login/configShareWx',
data: {
},
dataType: 'json',
async: false,
success: function(data) {
console.log(data);
if (data.code == 1) {
appid = data.appid;
timestamp = data.timestamp;
nonceStr = data.nonceStr;
signature = data.signature;
wx.config({
debug: true,
appId: appid,
timestamp: timestamp,
nonceStr: nonceStr,
signature: signature,
jsApiList: [
'updateAppMessageShareData',
]
});
wx.ready(function () { //需在用户可能点击分享按钮前就先调用
wx.updateAppMessageShareData({
title: '分享标题', // 分享标题
desc: '分享描述', // 分享描述
link: 'http://www.starplanet.cn/portal/enjoy/getEnjoyDetail?id=81', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: '', // 分享图标
success: function (e) {
// 设置成功
console.log(e);
}
})
});
} else {
console.log(data);
}
}
});
});
</script>
... ...