feat: add openCustomerServiceChat method
This commit is contained in:
parent
d73102a44a
commit
d3292dd064
@ -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 kfUrl, Callback callback) {
|
||||
if (api == null) {
|
||||
callback.invoke(NOT_REGISTERED);
|
||||
return;
|
||||
}
|
||||
// open customer service logic
|
||||
WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
|
||||
|
||||
req.corpId = this.appId;
|
||||
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")) {
|
||||
|
||||
@ -568,6 +568,16 @@ RCT_EXPORT_METHOD(pay:(NSDictionary *)data
|
||||
// callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
}
|
||||
|
||||
// 跳转微信客服
|
||||
RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)kfUrl
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init];
|
||||
req.corpid = self.appId; //企业ID
|
||||
req.url = kfUrl; //客服URL
|
||||
[WXApi sendReq:req completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - wx callback
|
||||
|
||||
-(void) onReq:(BaseReq*)req
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
47
src/index.d.ts
vendored
47
src/index.d.ts
vendored
@ -9,7 +9,11 @@ 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(kfUrl: string): Promise<string>;
|
||||
export function isWXAppInstalled(): Promise<boolean>;
|
||||
export function isWXAppSupportApi(): Promise<boolean>;
|
||||
export function getApiVersion(): Promise<string>;
|
||||
@ -39,9 +43,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 +124,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 +158,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 +176,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 +186,6 @@ declare module 'react-native-wechat-lib' {
|
||||
scene?: WXScene;
|
||||
}
|
||||
export function shareFile(
|
||||
data: ShareFileMetadata,
|
||||
data: ShareFileMetadata
|
||||
): Promise<{ errCode?: number; errStr?: string }>;
|
||||
}
|
||||
|
||||
26
src/index.js
26
src/index.js
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user