Skip to content

Commit

Permalink
feat: 修改设置企业微信参数
Browse files Browse the repository at this point in the history
  • Loading branch information
newbanker-damon committed Feb 28, 2022
1 parent 74ecb71 commit 45a8e2f
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 39 deletions.
25 changes: 10 additions & 15 deletions android/src/main/java/com/damoness/rn/umeng/ConfigureModule.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.damoness.rn.umeng;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;

import com.facebook.react.bridge.ReactMethod;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;

public class ConfigureModule extends ReactContextBaseJavaModule {

public class ConfigureModule extends ReactContextBaseJavaModule {

private ReactApplicationContext context;

public ConfigureModule(ReactApplicationContext reactContext) {
super(reactContext);
context = reactContext;
Expand All @@ -20,31 +21,25 @@ public String getName() {
return "DMNConfigure";
}


@ReactMethod
public void initApp(String appKey,String channel){
//初始化
UMConfigure.init(this.getReactApplicationContext(),appKey,channel,UMConfigure.DEVICE_TYPE_PHONE,"");
public void initApp(String appKey, String channel) {
// 初始化
UMConfigure.init(this.getReactApplicationContext(), appKey, channel, UMConfigure.DEVICE_TYPE_PHONE, "");
}


@ReactMethod
public void setWeChat(String appKey,String appSecret){
public void setWeChat(String appKey, String appSecret) {
// 微信设置
PlatformConfig.setWeixin(appKey,appSecret);
PlatformConfig.setWeixin(appKey, appSecret);
PlatformConfig.setWXFileProvider("com.tencent.sample2.fileprovider");

}


@ReactMethod
public void setWeChatWork(String appKey,String corpId,String agentId){
public void setWeChatWork(String appKey, String appSecret, String corpId, String agentId) {
// 企业微信设置
PlatformConfig.setWXWork(corpId,"",agentId,appKey);
PlatformConfig.setWXWork(corpId, appSecret, agentId, appKey);
PlatformConfig.setWXWorkFileProvider("com.tencent.sample2.fileprovider");
}




}
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import com.android.build.OutputFile

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
entryFile: "index.tsx",
entryFile: "index.js",
]

apply from: "../../node_modules/react-native/react.gradle"
Expand Down
1 change: 1 addition & 0 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"wechatWork": {
"appKey": "wwauth5a3c9b5d4dbd50d3000005",
"appSecret": "T4rIOiRRhGMLgSg1ysSAVBUongtNAw00oVs_cllULzk",
"corpId": "ww5a3c9b5d4dbd50d3",
"agentId": "1000005",
"ios_bundle_id": "com.zofund.crmmanage.test",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = X3384B9A6U;
DEVELOPMENT_TEAM = 8XXP5W7RV4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = ReactNativeUmengExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.8.4;
Expand All @@ -314,6 +315,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.zofund.crmmanage.test;
PRODUCT_NAME = ReactNativeUmengExample;
PROVISIONING_PROFILE_SPECIFIER = "Development _com.zofund.crmmanage.test";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
ReferencedContainer = "container:ReactNativeUmengExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
26 changes: 18 additions & 8 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ import appJSON from '../app.json';

let { umeng, wechatWork, wechat } = appJSON;

Configure.initApp(umeng.appKey, 'RN');
Configure.setWeChat(wechat.appKey, wechat.appSecret, wechat.universalLink);
Configure.setWeChatWork(
wechatWork.appKey,
wechatWork.corpId,
wechatWork.agentId
);

const getCommonFunctionData = (platform: SharePlatform) => {
return [
{
Expand Down Expand Up @@ -80,6 +72,24 @@ const getCommonFunctionData = (platform: SharePlatform) => {
};

export default function App() {
React.useEffect(() => {
async function init() {
await Configure.initApp(umeng.appKey, 'RN');
await Configure.setWeChat(
wechat.appKey,
wechat.appSecret,
wechat.universalLink
);
await Configure.setWeChatWork(
wechatWork.appKey,
wechatWork.appSecret,
wechatWork.corpId,
wechatWork.agentId
);
}
init();
}, []);

return (
<SafeAreaView style={styles.container}>
<SectionList
Expand Down
25 changes: 21 additions & 4 deletions ios/UM/DMNConfigure.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ - (dispatch_queue_t)methodQueue
return dispatch_get_main_queue();
}

RCT_EXPORT_METHOD(initApp:(NSString *)appkey channel:(NSString *)channel)
RCT_EXPORT_METHOD(initApp:(NSString *)appkey
channel:(NSString *)channel
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
SEL sel = NSSelectorFromString(@"setWraperType:wrapperVersion:");
if ([UMConfigure respondsToSelector:sel]) {
Expand All @@ -28,12 +31,18 @@ - (dispatch_queue_t)methodQueue
[UMConfigure setLogEnabled:YES];//设置打开日志

[UMConfigure initWithAppkey:appkey channel:channel];

resolve(@(true));
}

/**
设置微信
*/
RCT_EXPORT_METHOD(setWeChat:(NSString *)appkey appSecret:(NSString *)appSecret universalLink:(NSString *)universalLink){
RCT_EXPORT_METHOD(setWeChat:(NSString *)appkey
appSecret:(NSString *)appSecret
universalLink:(NSString *)universalLink
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject){


//配置微信平台的Universal Links
Expand All @@ -44,20 +53,28 @@ - (dispatch_queue_t)methodQueue
/* 设置微信的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:appkey appSecret:appSecret redirectURL:nil];

resolve(@(true));
}


/**
设置企业微信
*/
RCT_EXPORT_METHOD(setWeChatWork:(NSString *)appkey corpId:(NSString *)corpId agentId:(NSString *)agentId){
RCT_EXPORT_METHOD(setWeChatWork:(NSString *)appkey
appSecret:(NSString *)appSecret
corpId:(NSString *)corpId
agentId:(NSString *)agentId
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject){

[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatWork appKey:appkey appSecret:nil redirectURL:nil];
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatWork appKey:appkey appSecret:appSecret redirectURL:nil];

//extraInitDic,企业微信增加了corpid和agentid,故在UMSocialGlobal的全局配置里面增加extraInitDic来存储额外的初始化参数。extraInitDic的key:corpId和agentId为固定值
[UMSocialGlobal shareInstance].extraInitDic =@{
@(UMSocialPlatformType_WechatWork):@{@"corpId":corpId,@"agentId":agentId}
};

resolve(@(true));
}

@end
8 changes: 4 additions & 4 deletions ios/UM/DMNShareModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ - (dispatch_queue_t)methodQueue
- (UMSocialPlatformType)platformType:(NSInteger)platform
{
switch (platform) {
case 0: // QQ
case 0: //QQ
return UMSocialPlatformType_QQ;
case 1: // Sina
case 1: //Sina
return UMSocialPlatformType_Sina;
case 2: // wechat
case 2: //wechat
return UMSocialPlatformType_WechatSession;
case 3:
case 3: //
return UMSocialPlatformType_WechatTimeLine;
case 4:
return UMSocialPlatformType_WechatWork;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"release": "release-it",
"example": "yarn --cwd example",
"pods": "cd example && pod-install --quiet",
"bootstrap": "yarn example && yarn && yarn pods"
"bootstrap": "yarn example && yarn && yarn pods",
"ar": "adb reverse tcp:8081 tcp:8081"
},
"keywords": [
"react-native",
Expand Down
16 changes: 11 additions & 5 deletions src/Configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const Configure = NativeModules.DMNConfigure;
* @param channel //渠道
* @returns
*/
export function initApp(appKey: string, channel: string) {
return Configure.initApp(appKey, channel);
export async function initApp(appKey: string, channel: string) {
return await Configure.initApp(appKey, channel);
}

/**
Expand All @@ -18,7 +18,7 @@ export function initApp(appKey: string, channel: string) {
* @param appSecret
* @param universalLink
*/
export function setWeChat(
export async function setWeChat(
appKey: string,
appSecret: string,
universalLink: string
Expand All @@ -33,9 +33,15 @@ export function setWeChat(
/**
* 设置企业微信
* @param appKey
* @param appSecret
* @param corpId
* @param agentId
*/
export function setWeChatWork(appKey: string, corpId: string, agentId: string) {
Configure.setWeChatWork(appKey, corpId, agentId);
export async function setWeChatWork(
appKey: string,
appSecret: string,
corpId: string,
agentId: string
) {
return await Configure.setWeChatWork(appKey, appSecret, corpId, agentId);
}

0 comments on commit 45a8e2f

Please sign in to comment.