import React, {Component} from 'react'; import { View, Image, Text, Alert, Platform, TouchableOpacity, } from 'react-native'; import * as WeChat from 'react-native-wechat'; import Login from './login'; import public_css from '../../source/css/public_css'; export default class login_head extends Component { constructor(props) { super(props); this.props.navigation.dangerouslyGetParent().setOptions({ tabBarVisible: false, }); } render() { return ( { this.loginWeChat(); }}> ); } componentDidMount(): void { WeChat.registerApp('wxc4f72f029a280bc4'); } 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) => { Alert.alert('登录授权发生错误:', err.message, [{text: '确定'}]); }); } else { Platform.OS == 'ios' ? Alert.alert('没有安装微信', '是否安装微信?', [ {text: '取消'}, {text: '确定', onPress: () => {}}, ]) : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [ {text: '确定'}, ]); } }); }; }