Skip to content

Commit 8a8c559

Browse files
AronAron
authored andcommitted
feat: 新增isRegistered方法
1 parent 553aaa4 commit 8a8c559

File tree

12 files changed

+92
-210
lines changed

12 files changed

+92
-210
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ const result = await ExpoWeChat.registerApp(wechatAppId, universalLink);
9494
# API
9595
以下是所有已支持的API:
9696
```typescript
97+
/**
98+
* 是否已经成功调用registerApp方法。
99+
*/
100+
isRegistered: boolean;
101+
97102
isWXAppInstalled(): Promise<boolean>;
98103
getApiVersion(): Promise<string>;
99104
getWXAppInstallUrl(): Promise<string | null>;

android/src/main/java/expo/modules/wechat/ExpoWeChatModuleTypes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class LaunchMiniProgramOptions : Record {
203203
var extraData: String? = null
204204
}
205205

206-
class WeChatPayOptions : Record {
206+
class PayOptions : Record {
207207
@Field
208208
var partnerId: String = ""
209209

android/src/main/java/expo/modules/wechat/ExpoWechatModule.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.graphics.Bitmap
55
import android.graphics.BitmapFactory
66
import android.util.Base64
77
import android.util.Log
8+
import android.util.Property
89
import androidx.core.content.FileProvider
910
import com.tencent.mm.opensdk.constants.ConstantsAPI
1011
import com.tencent.mm.opensdk.diffdev.DiffDevOAuthFactory
@@ -65,6 +66,7 @@ class ExpoWechatModule : Module(), IWXAPIEventHandler {
6566
var api: IWXAPI? = null;
6667
var wxAppId: String? = null;
6768
var logLevel: LogLevel? = null
69+
var isApiRegistered = false
6870

6971
// Each module class must implement the definition function. The definition consists of components
7072
// that describes the module's functionality and behavior.
@@ -96,11 +98,8 @@ class ExpoWechatModule : Module(), IWXAPIEventHandler {
9698
moduleInstance = this@ExpoWechatModule
9799
}
98100

99-
AsyncFunction("registerApp") { appId: String, universalLink: String ->
100-
wxAppId = appId;
101-
api = WXAPIFactory.createWXAPI(appContext.reactContext, appId, true)
102-
val result = api?.registerApp(appId) ?: false
103-
return@AsyncFunction result
101+
Property("isRegistered") {
102+
return@Property isApiRegistered
104103
}
105104

106105
AsyncFunction("isWXAppInstalled") {
@@ -114,7 +113,13 @@ class ExpoWechatModule : Module(), IWXAPIEventHandler {
114113
AsyncFunction("getWXAppInstallUrl") {
115114
return@AsyncFunction null
116115
}
117-
116+
AsyncFunction("registerApp") { appId: String, universalLink: String ->
117+
wxAppId = appId;
118+
api = WXAPIFactory.createWXAPI(appContext.reactContext, appId, true)
119+
val result = api?.registerApp(appId) ?: false
120+
isApiRegistered = result
121+
return@AsyncFunction result
122+
}
118123
AsyncFunction("startLogByLevel") { level: String ->
119124
logLevel = LogLevel.fromString(level)
120125
api?.setLogImpl(object : ILog {
@@ -538,7 +543,7 @@ class ExpoWechatModule : Module(), IWXAPIEventHandler {
538543
}
539544
}
540545

541-
AsyncFunction("pay") { options: WeChatPayOptions, promise: Promise ->
546+
AsyncFunction("pay") { options: PayOptions, promise: Promise ->
542547
if (api != null) {
543548
val req = PayReq()
544549
req.appId = wxAppId

example/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function App() {
1818
const [miniProgramId, setMiniProgramId] = useState("");
1919
const [miniProgramPath, setMiniProgramPath] = useState("");
2020

21-
const [miniPrgramIdToLaunch, setMiniPrgramIdToLaunch] = useState("");
21+
const [miniProgramIdToLaunch, setMiniProgramIdToLaunch] = useState("");
2222

2323
const onAuthResult = useEvent(ExpoWechat, "onAuthResult");
2424
const wechatAppId = process.env.EXPO_PUBLIC_WECHAT_APP_ID;
@@ -166,11 +166,11 @@ export default function App() {
166166
return;
167167
}
168168
const result = ExpoWechat.launchMiniProgram({
169-
id: miniPrgramIdToLaunch,
169+
id: miniProgramIdToLaunch,
170170
type: "release",
171171
});
172172
console.log("Share to wechat timeline result:", result);
173-
}, [miniPrgramIdToLaunch]);
173+
}, [miniProgramIdToLaunch]);
174174

175175
return (
176176
<ScrollView
@@ -240,8 +240,8 @@ export default function App() {
240240
placeholder="小程序ID"
241241
clearButtonMode="while-editing"
242242
keyboardType="numeric"
243-
value={miniPrgramIdToLaunch}
244-
onChangeText={setMiniPrgramIdToLaunch}
243+
value={miniProgramIdToLaunch}
244+
onChangeText={setMiniProgramIdToLaunch}
245245
style={styles.textInput}
246246
/>
247247
<Button title="启动小程序" onPress={onLaunchMiniProgram} />

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ PODS:
6868
- ReactCommon/turbomodule/bridging
6969
- ReactCommon/turbomodule/core
7070
- Yoga
71-
- ExpoWechat (0.1.7):
71+
- ExpoWechat (0.1.8):
7272
- ExpoModulesCore
7373
- WechatOpenSDK-XCFramework (~> 2.0.5)
7474
- fast_float (6.1.4)
@@ -1992,7 +1992,7 @@ SPEC CHECKSUMS:
19921992
ExpoImagePicker: 0963da31800c906e01c03e25d7c849f16ebf02a2
19931993
ExpoKeepAwake: bf0811570c8da182bfb879169437d4de298376e7
19941994
ExpoModulesCore: 5d37821c36f3781dcd0ea9a393800c90eaa6259d
1995-
ExpoWechat: 1a80f3e6b6982a6eeb7f6fcf1e605075632582f7
1995+
ExpoWechat: 55ef9d4cb0dfe88c5e7ff22b6d7779ce81902ee8
19961996
fast_float: 06eeec4fe712a76acc9376682e4808b05ce978b6
19971997
FBLazyVector: 84b955f7b4da8b895faf5946f73748267347c975
19981998
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
@@ -2061,7 +2061,7 @@ SPEC CHECKSUMS:
20612061
ReactCodegen: c63eda03ba1d94353fb97b031fc84f75a0d125ba
20622062
ReactCommon: 76d2dc87136d0a667678668b86f0fca0c16fdeb0
20632063
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
2064-
WechatOpenSDK-XCFramework: b072030c9eeee91dfff1856a7846f70f7b9a88ed
2064+
WechatOpenSDK-XCFramework: ff342ae616bb86df3d236aca38059dfd4bc4a949
20652065
Yoga: c758bfb934100bb4bf9cbaccb52557cee35e8bdf
20662066

20672067
PODFILE CHECKSUM: 5b32907b096d81603ff2d4698be6863e01f51d37

example/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/ExpoWeChatModuleTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct LaunchMiniProgramOptions : Record {
210210
var extraData: String?
211211
}
212212

213-
struct WeChatPayOptions : Record {
213+
struct PayOptions : Record {
214214
@Field
215215
var partnerId: String = ""
216216

ios/ExpoWechatModule.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public class ExpoWechatModule: Module {
3535
Self.moduleInstance = nil
3636
}
3737

38+
Property("isRegistered") {
39+
return isApiRegistered
40+
}
41+
3842
AsyncFunction("isWXAppInstalled") {
3943
return WXApi.isWXAppInstalled()
4044
}
@@ -53,7 +57,7 @@ public class ExpoWechatModule: Module {
5357

5458
AsyncFunction("registerApp") { (appId: String, universalLink: String) in
5559
let result = WXApi.registerApp(appId, universalLink: universalLink)
56-
isApiRegistered = true
60+
isApiRegistered = result
5761
return result
5862
}
5963

@@ -429,7 +433,7 @@ public class ExpoWechatModule: Module {
429433
}
430434
}
431435

432-
AsyncFunction("pay") { (options: WeChatPayOptions, promise: Promise) in
436+
AsyncFunction("pay") { (options: PayOptions, promise: Promise) in
433437
if (isApiRegistered) {
434438
let req = PayReq()
435439

0 commit comments

Comments
 (0)