@norcy/react-native-toolkit 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ import { getUniqueIdSync } from 'react-native-device-info';
4
4
  import { AppleLoginUtil } from './AppleLoginUtil';
5
5
  import { Notification } from './Notification';
6
6
  import { BuildInPrefs, PrefData } from './PrefData';
7
+ import { ToolkitConfig } from './Tool';
7
8
  import { WeChatLoginUtil } from './WeChatLoginUtil';
8
9
  import {
9
10
  LoginAuthDataType,
@@ -17,9 +18,6 @@ const AV = require('leancloud-storage');
17
18
 
18
19
  let CURRENT_USER: UserType | null = null;
19
20
 
20
- let WeiXinId = '';
21
- let WeiXinSecret = '';
22
-
23
21
  const AVUserToLocalUser = (user: User) => {
24
22
  return {
25
23
  nickname: user.get('nickname'),
@@ -120,11 +118,6 @@ const doLeanCloudLogin = async (
120
118
  };
121
119
 
122
120
  export const LoginManager = {
123
- setup: (WeChatId: string, WeChatSecret: string) => {
124
- WeiXinId = WeChatId;
125
- WeiXinSecret = WeChatSecret;
126
- },
127
-
128
121
  // 自动根据已有的 User 信息进行登录鉴权,如果 User 为空则失败
129
122
  autoLogin: async () => {
130
123
  const user = await AV.User.currentAsync();
@@ -198,8 +191,8 @@ export const LoginManager = {
198
191
  }
199
192
  } else if (type === LoginType.LoginTypeWeChat) {
200
193
  WeChatLoginUtil.doLogin(
201
- WeiXinId,
202
- WeiXinSecret,
194
+ ToolkitConfig.WeiXinId,
195
+ ToolkitConfig.WeiXinSecret,
203
196
  ({
204
197
  nickname,
205
198
  headimgurl,
@@ -345,8 +338,8 @@ export const LoginManager = {
345
338
 
346
339
  fetchWeChatAvatar: (callback: Function) => {
347
340
  WeChatLoginUtil.doLogin(
348
- WeiXinId,
349
- WeiXinSecret,
341
+ ToolkitConfig.WeiXinId,
342
+ ToolkitConfig.WeiXinSecret,
350
343
  ({ headimgurl }: { headimgurl: string }) => {
351
344
  callback({ headimgurl });
352
345
  }
package/src/PrefData.ts CHANGED
@@ -93,7 +93,7 @@ export const PrefData = {
93
93
  } else {
94
94
  _PrefDatas[key] = value;
95
95
  }
96
- console.log('读取配置结束');
96
+
97
97
  // console.log(
98
98
  // '配置读取结果:',
99
99
  // key,
@@ -102,6 +102,7 @@ export const PrefData = {
102
102
  // );
103
103
  }
104
104
 
105
+ console.log('读取配置结束');
105
106
  isDataLoaded = true;
106
107
  eventEmitter.emit('load');
107
108
  },
package/src/Tool.ts CHANGED
@@ -10,9 +10,19 @@ export interface ToolkitConfigType {
10
10
  AndroidStoreScheme: string;
11
11
  iOSReviewUrl: string;
12
12
  AndroidPackageName: string;
13
+
13
14
  AppWebsite: string;
15
+
14
16
  PolicyUrl: string;
15
17
  TermsUrl: string;
18
+
19
+ PushDeerUrl: string;
20
+
21
+ RC_API_KEY: string;
22
+ RC_ENTITLEMENT_ID: string;
23
+ WeChatPayServer: string;
24
+ WeiXinId: string;
25
+ WeiXinSecret: string;
16
26
  }
17
27
 
18
28
  export let ToolkitConfig: ToolkitConfigType;
@@ -192,4 +202,10 @@ export const Tool = {
192
202
  Linking.openURL(ToolkitConfig.AppWebsite);
193
203
  }
194
204
  },
205
+
206
+ notifyMe: async (text: string) => {
207
+ if (!__DEV__) {
208
+ await fetch(ToolkitConfig.PushDeerUrl + encodeURIComponent(text));
209
+ }
210
+ },
195
211
  };
@@ -2,20 +2,14 @@ import Purchases, { PurchasesPackage } from 'react-native-purchases';
2
2
  import * as WeChat from 'react-native-wechat-lib';
3
3
  import { ConfigDataModel } from './ConfigDataModel';
4
4
  import { LoginManager } from './LoginManager';
5
- import { Tool } from './Tool';
6
-
7
- let SERVER_URL = '';
5
+ import { Tool, ToolkitConfig } from './Tool';
8
6
 
9
7
  export const VipAndroidManager = {
10
- init: ({ WeChatPayServer }: { WeChatPayServer: string }) => {
11
- SERVER_URL = WeChatPayServer;
12
- },
13
-
14
8
  queryOrder: async (orderId?: string) => {
15
9
  const user = LoginManager.currentUser();
16
10
  // Step1:生成预订单
17
11
  try {
18
- const rawResponse = await fetch(SERVER_URL, {
12
+ const rawResponse = await fetch(ToolkitConfig.WeChatPayServer, {
19
13
  method: 'POST',
20
14
  headers: {
21
15
  'Accept': 'application/json',
@@ -64,7 +58,7 @@ export const VipAndroidManager = {
64
58
  try {
65
59
  const user = LoginManager.currentUser();
66
60
  // Step1:生成预订单
67
- const rawResponse = await fetch(SERVER_URL, {
61
+ const rawResponse = await fetch(ToolkitConfig.WeChatPayServer, {
68
62
  method: 'POST',
69
63
  headers: {
70
64
  'Accept': 'application/json',
package/src/VipManager.ts CHANGED
@@ -7,32 +7,17 @@ import { DevConfig } from './DevConfig';
7
7
  import { LoginManager } from './LoginManager';
8
8
  import { Notification } from './Notification';
9
9
  import { BuildInPrefs } from './PrefData';
10
- import { Tool } from './Tool';
10
+ import { Tool, ToolkitConfig } from './Tool';
11
11
  import { VipAndroidManager } from './VipAndroidManager';
12
12
  import { UserType } from './constant';
13
13
 
14
14
  let _customerInfo: CustomerInfo | null;
15
- let _RC_ENTITLEMENT_ID: string = '';
16
15
 
17
16
  export const VipManager = {
18
- init: ({
19
- RC_API_KEY,
20
- RC_ENTITLEMENT_ID,
21
- WeChatPayServer,
22
- }: {
23
- RC_API_KEY: string;
24
- RC_ENTITLEMENT_ID: string;
25
- WeChatPayServer: string;
26
- }) => {
17
+ init: () => {
27
18
  console.log('Vip 模块初始化');
28
19
 
29
- VipAndroidManager.init({ WeChatPayServer });
30
-
31
- _RC_ENTITLEMENT_ID = RC_ENTITLEMENT_ID;
32
-
33
- Purchases.configure({
34
- apiKey: RC_API_KEY,
35
- });
20
+ Purchases.configure({ apiKey: ToolkitConfig.RC_API_KEY });
36
21
 
37
22
  VipManager.refreshVip();
38
23
 
@@ -78,8 +63,9 @@ export const VipManager = {
78
63
 
79
64
  await VipManager.refreshVip(customerInfo);
80
65
  if (
81
- typeof customerInfo.entitlements.active[_RC_ENTITLEMENT_ID] !==
82
- 'undefined'
66
+ typeof customerInfo.entitlements.active[
67
+ ToolkitConfig.RC_ENTITLEMENT_ID
68
+ ] !== 'undefined'
83
69
  ) {
84
70
  console.log('购买成功');
85
71
  return { errorCode: 0 };