123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- import * as WeChat from 'react-native-wechat';
- import request from '../utils/request';
- import AndroidUtil from '../../util/AndroidUtil';
- WeChat.registerApp('wx51acc19c8f7a0f6f');
- export default class wechat {
-
- static wechatLogin(callback) {
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- WeChat.sendAuthRequest('snsapi_userinfo').then((result) => {
- var object = JSON.parse(JSON.stringify(result));
- var loginUrl =
- 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx51acc19c8f7a0f6f&secret=e830d45f497025041269ef6221140c3d&code=' +
- object['code'] +
- '&grant_type=authorization_code';
- request(loginUrl).then((res) => {
-
-
- var getUserUrl =
- 'https://api.weixin.qq.com/sns/userinfo?access_token=' +
- res['access_token'] +
- '&openid=' +
- res['openid'];
- request(getUserUrl).then((user) => {
- console.log('微信返回信息');
- console.log('user', user);
- console.log('====================================');
- callback(user);
- });
- });
- });
- } else {
- alert('请安装微信');
- }
- });
- }
-
- static shareToSessionText(descriptiontext) {
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- WeChat.shareToSession({
- type: 'text',
- description: descriptiontext
- })
- .then((result) => {
- console.log(result);
- })
- .catch((error) => {
- error(error.message);
- });
- } else {
- alert('请安装微信');
- }
- });
- }
-
- static shareToSessionNews(title_text, description_text, thumbImage_url, webpageUrl_url) {
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- WeChat.shareToSession({
- title: title_text,
- description: description_text,
- thumbImage: thumbImage_url,
- type: 'news',
- webpageUrl: webpageUrl_url
- }).catch((error) => {
- alert(error.message);
- });
- } else {
- alert('请安装微信');
- }
- });
- }
-
- static shareToTimelineText(description_text) {
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- WeChat.shareToTimeline({
- type: 'text',
- description: description_text
- }).catch((error) => {
- console.log(error.message);
- });
- } else {
- alert('请安装微信');
- }
- });
- }
-
- static shareToTimelineNews(title_text, description_text, thumbImage_url, webpageUrl_url) {
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- WeChat.shareToTimeline({
- title: title_text,
- description: description_text,
- thumbImage: thumbImage_url,
- type: 'news',
- webpageUrl: webpageUrl_url
- }).catch((error) => {
- console.log(error.message);
- });
- } else {
- alert('请安装微信');
- }
- });
- }
-
- static pay(partnerId, prepayId, nonceStr, timeStamp, packages, sign) {
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- WeChat.pay({
- partnerId: partnerId,
- prepayId: prepayId,
- nonceStr: nonceStr,
- timeStamp: timeStamp,
- package: packages,
- sign: sign
- })
- .then((requestJson) => {
-
- if (requestJson.errCode == '0') {
-
- }
- })
- .catch((err) => {
- alert('支付失败');
- });
- } else {
- alert('请安装微信');
- }
- });
- }
-
- static toMiniProgram(programId, path) {
- WeChat.toMiniProgram(programId, path);
- }
- }
|