weChat.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import * as WeChat from 'react-native-wechat';
  2. import {Alert, Platform} from 'react-native';
  3. //微信免登
  4. export const loginWeChat = () => {
  5. let scope = 'snsapi_userinfo';
  6. let state = 'wechat_sdk_demo';
  7. //判断微信是否安装
  8. WeChat.isWXAppInstalled().then(isInstalled => {
  9. if (isInstalled) {
  10. //发送授权请求
  11. WeChat.sendAuthRequest(scope, state)
  12. .then(responseCode => {
  13. //返回code码,通过code获取access_token
  14. console.log(responseCode);
  15. // this.getAccessToken(responseCode.code);
  16. })
  17. .catch(err => {
  18. return Alert.alert('登录授权发生错误:', err.message, [{text: '确定'}]);
  19. });
  20. } else {
  21. return Platform.OS == 'ios'
  22. ? Alert.alert('没有安装微信', '是否安装微信?', [
  23. {text: '取消'},
  24. {text: '确定', onPress: () => {}},
  25. ])
  26. : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [
  27. {text: '确定'},
  28. ]);
  29. }
  30. });
  31. };