IOS8以上,WKWebview内核下, 应该需要严格签名url 去掉 # 号后面,否则会报错,config:invalid signature,在安卓下或UIWebview 都不会报错,微信分享朋友接口等接口出错,支付接口不会报错。
示例代码,URL:为签名url
this
.
$http
.
post(
'
/index.php/weixin/Get/jssdk
'
,
{url
:
document
.
URL
})
.
then(
(
response
)
=>
{
let
res
=
response
.
data
if (
res
.
code
===
'
04
')
{
return
}
let
wxjssdk
=
res
.
wxjssdk
wx
.
config(
{debug
:
wxjssdk
.
debug
,
appId
:
wxjssdk
.
appId
,
timestamp
:
wxjssdk
.
timestamp
,
nonceStr
:
wxjssdk
.
nonceStr
,
signature
:
wxjssdk
.
signature
,
jsApiList
:
wxjssdk
.
jsApiList
})
wx
.
ready(
function
()
{
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
wx
.
onMenuShareTimeline(
{
title
:
'
测试!!!
'
,
// 分享标题
link
:
link
,
// 分享链接
imgUrl
:
imgUrl
,
// 分享图标
success
:
function
()
{
// 用户确认分享后执行的回调函数
},
cancel
:
function
()
{
// 用户取消分享后执行的回调函数
console
.
log(
link)
}
})
// 朋友
wx
.
onMenuShareAppMessage(
{
title
:
title
,
// 分享标题
desc
:
'测试
!!!
'
,
// 分享描述
link
:
link
,
// 分享链接
imgUrl
:
imgUrl
,
// 分享图标
type
:
''
,
// 分享类型,music、video或link,不填默认为link
dataUrl
:
''
,
// 如果type是music或video,则要提供数据链接,默认为空
success
:
function
()
{
// 用户确认分享后执行的回调函数
},
cancel
:
function
()
{
// 用户取消分享后执行的回调函数
console
.
log(
link)
}
})
wx
.
onMenuShareQQ(
{
title
:
title
,
// 分享标题
desc
:
'测试
!!!
'
,
// 分享描述
link
:
link
,
// 分享链接
imgUrl
:
imgUrl
,
// 分享图标
success
:
function
()
{
// 用户确认分享后执行的回调函数
},
cancel
:
function
()
{
// 用户取消分享后执行的回调函数
}
})
})
wx
.
error(
p
=>
{
window.alert
(
p
)
})
},
(
response
)
=>
{})
服务端只需取得:document.URL 的 #前面
php代码, $url 为发送微信到服务器,获取token的url
$tmp = explode("#",$url);
$url = $tmp[0];