问题描述
APP项目使用React Native,需要使用微信分享接口,就用到react-native-wechat组建。项目中两个模块,一个产品列表模块,一个文档列表模块,都可以分享,现在出现很奇怪的问题,就是文档模块的分享是可以打开微信并分享的,但是产品模块的分享却老是没有反应
相关代码
分享操作的代码如下:
WeChat.isWXAppInstalled().then((isInstalled) => {
console.log("微信isInstalled:" + isInstalled);
//是否安装微信
if(isInstalled){
WeChat.isWXAppSupportApi().then((isSupportApi) => {
console.log("微信分享isSupportApi:" + isSupportApi);
//是否支持微信开放接口
if(isSupportApi){
var shareData = {
type: 'news',
title: Share_reducers.ShareName,
description: Share_reducers.description?Share_reducers.description:'来自'+Login_reducers.userInfo.CompanyName+'的分享',
webpageUrl: Share_reducers.emailUrl+'&logId='+res+'&shareType=1',
thumbImage: thumb,
};
console.log("----------------------------------微信分享-------------------------------");
console.log(JSON.stringify(shareData));
console.log("----------------------------------微信分享-------------------------------");
//分享到好友
WeChat.shareToSession(shareData).then(res=>{
console.log("......shared........");
dispatch({
type: 'hide',
});
msg('分享成功');
}).catch(res=>{
console.log("......error........");
console.log(JSON.stringify(res));
msg('分享取消');
dispatch({
type: 'hide',
});
}).finally(function() {
console.log("finally..................................");
console.log(JSON.stringify(arguments));
});
}else{
msg( '不支持微信开放接口' );
dispatch({
type: 'hide',
});
}
});
}else{
msg( '没有安装微信软件,请您安装微信之后再试' );
dispatch({
type: 'hide',
});
}
});
使用安卓调试时,文档分享打印日志如下:
07-11 14:45:31.926: I/ReactNativeJS(10950): 微信isInstalled:true
07-11 14:45:31.965: I/ReactNativeJS(10950): 微信分享isSupportApi:true
07-11 14:45:31.965: I/ReactNativeJS(10950): ----------------------------------微信分享-------------------------------
07-11 14:45:31.965: I/ReactNativeJS(10950): {"type":"news","title":"制药&医疗","description":"来自高怡机械的分享","webpageUrl":"http://admin.zsgc.online/zhizaohui/file_list.html?shareId=B504144231070969&id=298&shareFileType=1&platform=app&logId=1958&shareType=1","thumbImage":"http://console.zsgc.online/static/web/img/ic_launcher.png"}
07-11 14:45:31.965: I/ReactNativeJS(10950): ----------------------------------微信分享-------------------------------
07-11 14:46:24.131: I/ReactNativeJS(10950): ......shared........
07-11 14:46:24.167: I/ReactNativeJS(10950): finally..................................
07-11 14:46:24.167: I/ReactNativeJS(10950): {}
产品分享日志如下:
07-11 14:46:56.919: I/ReactNativeJS(10950): 微信isInstalled:true
07-11 14:46:56.958: I/ReactNativeJS(10950): 微信分享isSupportApi:true
07-11 14:46:56.959: I/ReactNativeJS(10950): ----------------------------------微信分享-------------------------------
07-11 14:46:56.959: I/ReactNativeJS(10950): {"type":"news","title":"Dyson","description":"来自高怡机械的分享","webpageUrl":"http://admin.zsgc.online/zhizaohui/product_center.html?shareId=B504144231070969&id=171&type=1&platform=app&logId=1959&shareType=1","thumbImage":"http://zsgcapp.oss-cn-hongkong.aliyuncs.com/2018/05/10/54a2f55d5b10e147a6df99a1cec7339e.png"}
07-11 14:46:56.959: I/ReactNativeJS(10950): ----------------------------------微信分享-------------------------------
找到原因了,原来是因为分享的时候thumbImage过大,基本上都在700KB以上,使用nginx的http_image_filter_module在分享的时候处理一下图片即可,如果使用第三方的图片存储,如阿里云OSS,有提供相应的处理功能如:域名/sample.jpg?x-oss-process=style/stylename,这些都是可以在阿里云控制台配置即可