import * as WeChat from 'react-native-wechat-lib'; import {Alert, Platform} from 'react-native'; //微信免登 export const loginWeChat = () => { let scope = 'snsapi_userinfo'; let state = 'wechat_sdk_demo'; //判断微信是否安装 WeChat.isWXAppInstalled().then((isInstalled) => { if (isInstalled) { //发送授权请求 WeChat.sendAuthRequest(scope, state) .then((responseCode) => { //返回code码,通过code获取access_token console.log(responseCode); // this.getAccessToken(responseCode.code); }) .catch((err) => { return Alert.alert('登录授权发生错误:', err.message, [ {text: '确定'}, ]); }); } else { return Platform.OS == 'ios' ? Alert.alert('没有安装微信', '是否安装微信?', [ {text: '取消'}, {text: '确定', onPress: () => {}}, ]) : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [ {text: '确定'}, ]); } }); }; // 微信分享好友和朋友圈 export const weChatShare = (title, desc, type, userId, activityId) => { WeChat.shareWebpage({ title: title, description: desc, thumbImageUrl: 'https://www.chtax.cn/favicon.png', webpageUrl: 'https://www.chtax.cn/marketing/yinliu/#/s?participantId=' + userId + '&campaignId=' + activityId + '&reqChannel=' + 3 + '', scene: type, }).then((value) => { console.log(value.errCode); console.log(value.errStr); }); };