Code Monkey home page Code Monkey logo

Comments (14)

fa-ge avatar fa-ge commented on July 22, 2024

啥版本的QQ浏览器?我不能保证所有的浏览器都能唤起浏览器分享的组件,所以如果对于不支持的可以在catch里做降级处理!

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

本来是可以的,不知道是不是我引入了sea.js引起的。

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

var browser = mobileBrowserType(); //判断浏览器类型
var nativeShare;
//多模块模式
seajs.use(['https://res.wx.qq.com/open/js/jweixin-1.0.0.js', 'NativeShare.js'], function(a, b) {
if(browser == 'weixin'){
weixinShare(a);
} else {
nativeShare = new NativeShare();
var shareData = {
title: share_title,
desc: share_desc,
// 如果是微信该link的域名必须要在微信后台配置的安全域名之内的。
link: share_link,
icon: share_imgUrl
};
nativeShare.setShareData(shareData);
}
});
function call(command) {
try {
if(browser == 'weixin') {
$.toast('请点击右上角分享内容');
return;
}
nativeShare.call(command)
} catch (err) {
// 如果不支持,你可以在这里做降级处理
alert(err.message);
alert(browser);
if(browser == 'i_safari'){
$.popup(".popup-shareTips");
} else {
var errMsg = '';
switch (command){
case 'weibo':
errMsg = '请手动分享到微博';
break;
case 'wechatFriend':
errMsg = '请手动分享给微信好友';
break;
case 'wechatTimeline':
errMsg = '请手动分享到微信朋友圈';
break;
}
$.toast(errMsg);
}
}
}
function setTitle(title) {
nativeShare.setShareData({
title: title
})
}

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

因为在微信浏览器里只能引入了微信分享的js后,微信的分享调用不起来,所以我用sea.js把两个js分别引入了

from nativeshare.

fa-ge avatar fa-ge commented on July 22, 2024

当你在new NativeShare()的时候,库会检查你当前的环境是不是在微信中,如果是,就会去下载微信分享依赖的js文件。微信中你只需要设置appid.....一系列的配置,文档中有写。其他方法都是一样的。至于目前NativeShare应该是不支持seajs引入的!

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

哦哦~!
我不引入微信的js了,设置了appid,但是报{ "errMsg": "config:invalid appid" },可我明明设置了appid啊

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

var nativeShare = new NativeShare({
appId: '{$wx_params.appid}', // 必填,公众号的唯一标识
timestamp: Number('{$wx_params.timestamp}'), // 必填,生成签名的时间戳
nonceStr: '{$wx_params.noncestr}', // 必填,生成签名的随机串
signature: '{$wx_params.sign}'// 必填,签名
});
nativeShare.setShareData({
title: share_title,
desc: share_desc,
// 如果是微信该link的域名必须要在微信后台配置的安全域名之内的。
link: share_link,
icon: share_imgUrl
});

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

报错是这这样的:
输入参数:
{ "timestamp": "undefined", "jsApiList": [ "onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone" ] }
输出参数:
{ "errMsg": "config:invalid appid" }

from nativeshare.

fa-ge avatar fa-ge commented on July 22, 2024

你可以打断点进去看看,是否这些值真的存在?

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

在NativeShare.js里没有找到appId,timestamp,nonceStr,signature这几个变量

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

找到了,参数少传了
var nativeShare = new NativeShare({wechatConfig: {
appId: '{$wx_params.appid}',
timestamp: Number('{$wx_params.timestamp}'),
nonceStr: '{$wx_params.noncestr}',
signature: '{$wx_params.sign}'
}});
这样传就可以了

from nativeshare.

fa-ge avatar fa-ge commented on July 22, 2024

真的万分抱歉,文档写坑了!真亏你能找到!

from nativeshare.

Cooperhush avatar Cooperhush commented on July 22, 2024

嗯。我是找了好久才找到的!/(ㄒoㄒ)/~~

from nativeshare.

fa-ge avatar fa-ge commented on July 22, 2024

厉害👍

from nativeshare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.