1234567891011121314151617181920212223242526272829303132 |
- import * as WeChat from 'react-native-wechat';
- 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: '确定'},
- ]);
- }
- });
- };
|