Skip to content

Commit 2c77427

Browse files
Merge pull request #245 from BambooSword/master
feat: add openCustomerServiceChat method
2 parents d73102a + 9ba05c1 commit 2c77427

File tree

5 files changed

+85
-25
lines changed

5 files changed

+85
-25
lines changed

android/src/main/java/com/wechatlib/WeChatLibModule.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.tencent.mm.opensdk.modelbase.BaseReq;
3333
import com.tencent.mm.opensdk.modelbase.BaseResp;
3434
import com.tencent.mm.opensdk.modelbiz.ChooseCardFromWXCardPackage;
35+
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat;
3536
import com.tencent.mm.opensdk.modelmsg.SendAuth;
3637
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
3738
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX;
@@ -672,6 +673,20 @@ public void pay(ReadableMap data, Callback callback) {
672673
callback.invoke(api.sendReq(payReq) ? null : INVOKE_FAILED);
673674
}
674675

676+
@ReactMethod
677+
public void openCustomerServiceChat(String corpId, String kfUrl, Callback callback) {
678+
if (api == null) {
679+
callback.invoke(NOT_REGISTERED);
680+
return;
681+
}
682+
// open customer service logic
683+
WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
684+
685+
req.corpId = corpId;
686+
req.url = kfUrl;
687+
callback.invoke(null, api.sendReq(req));
688+
}
689+
675690
private void _share(final int scene, final ReadableMap data, final Callback callback) {
676691
Uri uri = null;
677692
if (data.hasKey("thumbImage")) {

ios/WechatLib.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,17 @@ - (NSData *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength {
568568
// callback(@[success ? [NSNull null] : INVOKE_FAILED]);
569569
}
570570

571+
// 跳转微信客服
572+
RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
573+
:(NSString *)kfUrl
574+
:(RCTResponseSenderBlock)callback)
575+
{
576+
WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init];
577+
req.corpid = corpId; //企业ID
578+
req.url = kfUrl; //客服URL
579+
[WXApi sendReq:req completion:nil];
580+
}
581+
571582
#pragma mark - wx callback
572583

573584
-(void) onReq:(BaseReq*)req

ios/WechatLib.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
86D0366429A4BF3E00A01343 /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 86D0365E29A4BF2600A01343 /* libWeChatSDK.a */; };
11-
86D0366529A4BF5900A01343 /* WechatLib.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* WechatLib.m */; };
11+
86D0366529A4BF5900A01343 /* WechatLib.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* WechatLib.mm */; };
1212
/* End PBXBuildFile section */
1313

1414
/* Begin PBXCopyFilesBuildPhase section */
@@ -31,7 +31,7 @@
3131
86D0366029A4BF2700A01343 /* WechatAuthSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WechatAuthSDK.h; sourceTree = "<group>"; };
3232
86D0366129A4BF2700A01343 /* WXApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApi.h; sourceTree = "<group>"; };
3333
B3E7B5881CC2AC0600A0062D /* WechatLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WechatLib.h; sourceTree = "<group>"; };
34-
B3E7B5891CC2AC0600A0062D /* WechatLib.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WechatLib.m; sourceTree = "<group>"; };
34+
B3E7B5891CC2AC0600A0062D /* WechatLib.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WechatLib.mm; sourceTree = "<group>"; };
3535
/* End PBXFileReference section */
3636

3737
/* Begin PBXFrameworksBuildPhase section */
@@ -63,7 +63,7 @@
6363
86D0366129A4BF2700A01343 /* WXApi.h */,
6464
86D0365D29A4BF2600A01343 /* WXApiObject.h */,
6565
B3E7B5881CC2AC0600A0062D /* WechatLib.h */,
66-
B3E7B5891CC2AC0600A0062D /* WechatLib.m */,
66+
B3E7B5891CC2AC0600A0062D /* WechatLib.mm */,
6767
134814211AA4EA7D00B7C361 /* Products */,
6868
86D0366329A4BF3E00A01343 /* Frameworks */,
6969
);
@@ -133,7 +133,7 @@
133133
isa = PBXSourcesBuildPhase;
134134
buildActionMask = 2147483647;
135135
files = (
136-
86D0366529A4BF5900A01343 /* WechatLib.m in Sources */,
136+
86D0366529A4BF5900A01343 /* WechatLib.mm in Sources */,
137137
);
138138
runOnlyForDeploymentPostprocessing = 0;
139139
};

src/index.d.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ enum WXScene {
99
}
1010

1111
declare module 'react-native-wechat-lib' {
12-
export function registerApp(appId: string, universalLink?: string): Promise<boolean>;
12+
export function registerApp(
13+
appId: string,
14+
universalLink?: string
15+
): Promise<boolean>;
16+
export function openCustomerServiceChat(
17+
corpId: string,
18+
kfUrl: string
19+
): Promise<string>;
1320
export function isWXAppInstalled(): Promise<boolean>;
1421
export function isWXAppSupportApi(): Promise<boolean>;
1522
export function getApiVersion(): Promise<string>;
@@ -39,9 +46,20 @@ declare module 'react-native-wechat-lib' {
3946
state?: string;
4047
returnKey?: string;
4148
}
42-
export function sendAuthRequest(scope: string | string[], state?: string): Promise<AuthResponse>;
49+
export function sendAuthRequest(
50+
scope: string | string[],
51+
state?: string
52+
): Promise<AuthResponse>;
4353
export interface ShareMetadata {
44-
type: 'news' | 'text' | 'imageUrl' | 'imageFile' | 'imageResource' | 'video' | 'audio' | 'file';
54+
type:
55+
| 'news'
56+
| 'text'
57+
| 'imageUrl'
58+
| 'imageFile'
59+
| 'imageResource'
60+
| 'video'
61+
| 'audio'
62+
| 'file';
4563
thumbImage?: string;
4664
description?: string;
4765
webpageUrl?: string;
@@ -109,31 +127,31 @@ declare module 'react-native-wechat-lib' {
109127
}
110128

111129
export function shareText(
112-
message: ShareTextMetadata,
130+
message: ShareTextMetadata
113131
): Promise<{ errCode?: number; errStr?: string }>;
114132
export function shareImage(
115-
message: ShareImageMetadata,
133+
message: ShareImageMetadata
116134
): Promise<{ errCode?: number; errStr?: string }>;
117135
export function shareLocalImage(
118-
message: ShareImageMetadata,
136+
message: ShareImageMetadata
119137
): Promise<{ errCode?: number; errStr?: string }>;
120138
export function shareMusic(
121-
message: ShareMusicMetadata,
139+
message: ShareMusicMetadata
122140
): Promise<{ errCode?: number; errStr?: string }>;
123141
export function shareVideo(
124-
message: ShareVideoMetadata,
142+
message: ShareVideoMetadata
125143
): Promise<{ errCode?: number; errStr?: string }>;
126144
export function shareWebpage(
127-
message: ShareWebpageMetadata,
145+
message: ShareWebpageMetadata
128146
): Promise<{ errCode?: number; errStr?: string }>;
129147
export function shareMiniProgram(
130-
message: ShareMiniProgramMetadata,
148+
message: ShareMiniProgramMetadata
131149
): Promise<{ errCode?: number; errStr?: string }>;
132150
export function launchMiniProgram(
133-
message: LaunchMiniProgramMetadata,
151+
message: LaunchMiniProgramMetadata
134152
): Promise<{ errCode?: number; errStr?: string }>;
135153
export function subscribeMessage(
136-
message: SubscribeMessageMetadata,
154+
message: SubscribeMessageMetadata
137155
): Promise<{ errCode?: number; errStr?: string }>;
138156
export interface PaymentLoad {
139157
partnerId: string;
@@ -143,7 +161,9 @@ declare module 'react-native-wechat-lib' {
143161
package: string;
144162
sign: string;
145163
}
146-
export function pay(payload: PaymentLoad): Promise<{ errCode?: number; errStr?: string }>;
164+
export function pay(
165+
payload: PaymentLoad
166+
): Promise<{ errCode?: number; errStr?: string }>;
147167

148168
export interface ChooseInvoice {
149169
signType?: string;
@@ -159,7 +179,7 @@ declare module 'react-native-wechat-lib' {
159179
}
160180

161181
export function chooseInvoice(
162-
data: ChooseInvoice,
182+
data: ChooseInvoice
163183
): Promise<{ errCode?: number; errStr?: string; cards: Invoice[] }>;
164184

165185
export interface ShareFileMetadata {
@@ -169,6 +189,6 @@ declare module 'react-native-wechat-lib' {
169189
scene?: WXScene;
170190
}
171191
export function shareFile(
172-
data: ShareFileMetadata,
192+
data: ShareFileMetadata
173193
): Promise<{ errCode?: number; errStr?: string }>;
174194
}

src/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,19 @@ export const getApiVersion = wrapApi(WeChat.getApiVersion);
146146
* @return {Promise}
147147
*/
148148
export const openWXApp = wrapApi(WeChat.openWXApp);
149+
/**
150+
* Open wechat app
151+
* @method openCustomerServiceChat
152+
* @return {Promise}
153+
*/
154+
export const openCustomerServiceChat = wrapApi(WeChat.openCustomerServiceChat);
149155

150156
// wrap the APIs
151-
const nativeShareToTimeline = wrapApi(WeChat.shareToTimeline);
157+
// const nativeShareToTimeline = wrapApi(WeChat.shareToTimeline);
152158
const nativeLaunchMiniProgram = wrapApi(WeChat.launchMiniProgram);
153-
const nativeShareToSession = wrapApi(WeChat.shareToSession);
159+
// const nativeShareToSession = wrapApi(WeChat.shareToSession);
154160
const nativeShareToFavorite = wrapApi(WeChat.shareToFavorite);
155-
const nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest);
161+
// const nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest);
156162
const nativeShareText = wrapApi(WeChat.shareText);
157163
const nativeShareImage = wrapApi(WeChat.shareImage);
158164
const nativeShareLocalImage = wrapApi(WeChat.shareLocalImage);
@@ -385,14 +391,22 @@ export function shareMiniProgram(data) {
385391
* @param {Integer} miniProgramType - 拉起小程序的类型. 0-正式版 1-开发版 2-体验版
386392
* @param {String} path - 拉起小程序页面的可带参路径,不填默认拉起小程序首页
387393
*/
388-
export function launchMiniProgram({ userName, miniProgramType = 0, path = '' }) {
394+
export function launchMiniProgram({
395+
userName,
396+
miniProgramType = 0,
397+
path = '',
398+
}) {
389399
return new Promise((resolve, reject) => {
390-
if (miniProgramType !== 0 && miniProgramType !== 1 && miniProgramType !== 2) {
400+
if (
401+
miniProgramType !== 0 &&
402+
miniProgramType !== 1 &&
403+
miniProgramType !== 2
404+
) {
391405
reject(
392406
new WechatError({
393407
errStr: '拉起小程序的类型不对,0-正式版 1-开发版 2-体验版',
394408
errCode: -1,
395-
}),
409+
})
396410
);
397411
return;
398412
}

0 commit comments

Comments
 (0)