weChat.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import * as WeChat from 'react-native-wechat-lib';
  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, [
  19. {text: '确定'},
  20. ]);
  21. });
  22. } else {
  23. return Platform.OS == 'ios'
  24. ? Alert.alert('没有安装微信', '是否安装微信?', [
  25. {text: '取消'},
  26. {text: '确定', onPress: () => {}},
  27. ])
  28. : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [
  29. {text: '确定'},
  30. ]);
  31. }
  32. });
  33. };
  34. // 微信分享好友和朋友圈
  35. export const weChatShare = (title, desc, type, userId, activityId) => {
  36. WeChat.shareWebpage({
  37. title: title,
  38. description: desc,
  39. thumbImageUrl: 'https://www.chtax.cn/favicon.png',
  40. webpageUrl:
  41. 'https://www.chtax.cn/marketing/yinliu/#/s?participantId=' +
  42. userId +
  43. '&campaignId=' +
  44. activityId +
  45. '&reqChannel=' +
  46. 3 +
  47. '',
  48. scene: type,
  49. }).then((value) => {
  50. console.log(value.errCode);
  51. console.log(value.errStr);
  52. });
  53. };