Merge pull request #245 from BambooSword/master

feat: add openCustomerServiceChat method
This commit is contained in:
snowfox 2023-07-01 16:41:27 +08:00 committed by GitHub
commit 2c774270cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 25 deletions

View File

@ -32,6 +32,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelbiz.ChooseCardFromWXCardPackage;
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX;
@ -672,6 +673,20 @@ public class WeChatLibModule extends ReactContextBaseJavaModule implements IWXAP
callback.invoke(api.sendReq(payReq) ? null : INVOKE_FAILED);
}
@ReactMethod
public void openCustomerServiceChat(String corpId, String kfUrl, Callback callback) {
if (api == null) {
callback.invoke(NOT_REGISTERED);
return;
}
// open customer service logic
WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
req.corpId = corpId;
req.url = kfUrl;
callback.invoke(null, api.sendReq(req));
}
private void _share(final int scene, final ReadableMap data, final Callback callback) {
Uri uri = null;
if (data.hasKey("thumbImage")) {

View File

@ -568,6 +568,17 @@ RCT_EXPORT_METHOD(pay:(NSDictionary *)data
// callback(@[success ? [NSNull null] : INVOKE_FAILED]);
}
// 跳转微信客服
RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
:(NSString *)kfUrl
:(RCTResponseSenderBlock)callback)
{
WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init];
req.corpid = corpId; //企业ID
req.url = kfUrl; //客服URL
[WXApi sendReq:req completion:nil];
}
#pragma mark - wx callback
-(void) onReq:(BaseReq*)req

View File

@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
86D0366429A4BF3E00A01343 /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 86D0365E29A4BF2600A01343 /* libWeChatSDK.a */; };
86D0366529A4BF5900A01343 /* WechatLib.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* WechatLib.m */; };
86D0366529A4BF5900A01343 /* WechatLib.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* WechatLib.mm */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -31,7 +31,7 @@
86D0366029A4BF2700A01343 /* WechatAuthSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WechatAuthSDK.h; sourceTree = "<group>"; };
86D0366129A4BF2700A01343 /* WXApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApi.h; sourceTree = "<group>"; };
B3E7B5881CC2AC0600A0062D /* WechatLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WechatLib.h; sourceTree = "<group>"; };
B3E7B5891CC2AC0600A0062D /* WechatLib.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WechatLib.m; sourceTree = "<group>"; };
B3E7B5891CC2AC0600A0062D /* WechatLib.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WechatLib.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -63,7 +63,7 @@
86D0366129A4BF2700A01343 /* WXApi.h */,
86D0365D29A4BF2600A01343 /* WXApiObject.h */,
B3E7B5881CC2AC0600A0062D /* WechatLib.h */,
B3E7B5891CC2AC0600A0062D /* WechatLib.m */,
B3E7B5891CC2AC0600A0062D /* WechatLib.mm */,
134814211AA4EA7D00B7C361 /* Products */,
86D0366329A4BF3E00A01343 /* Frameworks */,
);
@ -133,7 +133,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
86D0366529A4BF5900A01343 /* WechatLib.m in Sources */,
86D0366529A4BF5900A01343 /* WechatLib.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

50
src/index.d.ts vendored
View File

@ -9,7 +9,14 @@ enum WXScene {
}
declare module 'react-native-wechat-lib' {
export function registerApp(appId: string, universalLink?: string): Promise<boolean>;
export function registerApp(
appId: string,
universalLink?: string
): Promise<boolean>;
export function openCustomerServiceChat(
corpId: string,
kfUrl: string
): Promise<string>;
export function isWXAppInstalled(): Promise<boolean>;
export function isWXAppSupportApi(): Promise<boolean>;
export function getApiVersion(): Promise<string>;
@ -39,9 +46,20 @@ declare module 'react-native-wechat-lib' {
state?: string;
returnKey?: string;
}
export function sendAuthRequest(scope: string | string[], state?: string): Promise<AuthResponse>;
export function sendAuthRequest(
scope: string | string[],
state?: string
): Promise<AuthResponse>;
export interface ShareMetadata {
type: 'news' | 'text' | 'imageUrl' | 'imageFile' | 'imageResource' | 'video' | 'audio' | 'file';
type:
| 'news'
| 'text'
| 'imageUrl'
| 'imageFile'
| 'imageResource'
| 'video'
| 'audio'
| 'file';
thumbImage?: string;
description?: string;
webpageUrl?: string;
@ -109,31 +127,31 @@ declare module 'react-native-wechat-lib' {
}
export function shareText(
message: ShareTextMetadata,
message: ShareTextMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function shareImage(
message: ShareImageMetadata,
message: ShareImageMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function shareLocalImage(
message: ShareImageMetadata,
message: ShareImageMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function shareMusic(
message: ShareMusicMetadata,
message: ShareMusicMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function shareVideo(
message: ShareVideoMetadata,
message: ShareVideoMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function shareWebpage(
message: ShareWebpageMetadata,
message: ShareWebpageMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function shareMiniProgram(
message: ShareMiniProgramMetadata,
message: ShareMiniProgramMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function launchMiniProgram(
message: LaunchMiniProgramMetadata,
message: LaunchMiniProgramMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export function subscribeMessage(
message: SubscribeMessageMetadata,
message: SubscribeMessageMetadata
): Promise<{ errCode?: number; errStr?: string }>;
export interface PaymentLoad {
partnerId: string;
@ -143,7 +161,9 @@ declare module 'react-native-wechat-lib' {
package: string;
sign: string;
}
export function pay(payload: PaymentLoad): Promise<{ errCode?: number; errStr?: string }>;
export function pay(
payload: PaymentLoad
): Promise<{ errCode?: number; errStr?: string }>;
export interface ChooseInvoice {
signType?: string;
@ -159,7 +179,7 @@ declare module 'react-native-wechat-lib' {
}
export function chooseInvoice(
data: ChooseInvoice,
data: ChooseInvoice
): Promise<{ errCode?: number; errStr?: string; cards: Invoice[] }>;
export interface ShareFileMetadata {
@ -169,6 +189,6 @@ declare module 'react-native-wechat-lib' {
scene?: WXScene;
}
export function shareFile(
data: ShareFileMetadata,
data: ShareFileMetadata
): Promise<{ errCode?: number; errStr?: string }>;
}

View File

@ -146,13 +146,19 @@ export const getApiVersion = wrapApi(WeChat.getApiVersion);
* @return {Promise}
*/
export const openWXApp = wrapApi(WeChat.openWXApp);
/**
* Open wechat app
* @method openCustomerServiceChat
* @return {Promise}
*/
export const openCustomerServiceChat = wrapApi(WeChat.openCustomerServiceChat);
// wrap the APIs
const nativeShareToTimeline = wrapApi(WeChat.shareToTimeline);
// const nativeShareToTimeline = wrapApi(WeChat.shareToTimeline);
const nativeLaunchMiniProgram = wrapApi(WeChat.launchMiniProgram);
const nativeShareToSession = wrapApi(WeChat.shareToSession);
// const nativeShareToSession = wrapApi(WeChat.shareToSession);
const nativeShareToFavorite = wrapApi(WeChat.shareToFavorite);
const nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest);
// const nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest);
const nativeShareText = wrapApi(WeChat.shareText);
const nativeShareImage = wrapApi(WeChat.shareImage);
const nativeShareLocalImage = wrapApi(WeChat.shareLocalImage);
@ -385,14 +391,22 @@ export function shareMiniProgram(data) {
* @param {Integer} miniProgramType - 拉起小程序的类型. 0-正式版 1-开发版 2-体验版
* @param {String} path - 拉起小程序页面的可带参路径不填默认拉起小程序首页
*/
export function launchMiniProgram({ userName, miniProgramType = 0, path = '' }) {
export function launchMiniProgram({
userName,
miniProgramType = 0,
path = '',
}) {
return new Promise((resolve, reject) => {
if (miniProgramType !== 0 && miniProgramType !== 1 && miniProgramType !== 2) {
if (
miniProgramType !== 0 &&
miniProgramType !== 1 &&
miniProgramType !== 2
) {
reject(
new WechatError({
errStr: '拉起小程序的类型不对0-正式版 1-开发版 2-体验版',
errCode: -1,
}),
})
);
return;
}