目录
接入说明:
任何需要调用企业微信API的应用,都需要先在企业微信管理后台创建一个应用,设置完成后,即可使用对应的功能。
企业微信分享的设置,复用企业微信授权登录的设置,设置以后登录、分享任何一个都可以使用。
SDK文件包括 libWXWorkApi.a,WWKApi.h,WWKApiObject.h 三个。
请前往 资源下载 下载最新SDK包sdk.zip
SDK名称:企业微信登录/分享SDK
版本号: 0.16
主要功能:通过企业微信登录/分享SDK,企业可在自建的app引入sdk,从而可使用企业微信账号登录app,并且在app中分享消息到企业微信。
使用说明:详见本接入指南
开发者:深圳市腾讯计算机系统有限公司
隐私政策:请接入企业微信登录/分享 SDK的开发者,认真阅读《企业微信登录/分享SDK个人信息保护规则》,并确保对企业微信登录/分享SDK的接入使用情况符合上述规则的相关要求。
下载包包含4个文件,其名称和含义分别是:
WWKApi.h 定义SDK接口的头文件
WWKObject.h 定义SDK接口用来进行参数传递的对象
libWXWorkApi.a 第三方工程需要引用的SDK静态库文件
demo.tar.gz 一个供参考的企业微信iOS端SDK使用的示例工程,这个工程介绍了当前版本SDK提供的所有接口的使用方法
#import "AppDelegate.h"
#import "WWKApi.h"
@interface AppDelegate () <WWKApiDelegate>
@end
@implementation AppDelegate
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/*! @brief 调用这个方法前需要先到管理端进行注册 走管理端的注册方式
*
* 在管理端通过注册(可能需要等待审批),获得schema+corpid+agentid
* @param registerApp 第三方App的Schema
* @param corpId 第三方App所属企业的ID
* @param agentId 第三方App在企业内部的ID
*/
[WWKApi registerApp:@"wwauth700000a5f2191000014" corpId:@"ww700000a5f2191" agentId:@"1000014"];
return YES;
}
2.重写AppDelegate的handleOpenURL和openURL方法,第三方iOS App需要在这两个方法中调用SDK的handleOpenURL接口方法,让SDK有机会在第三方App内部处理SSO结果返回给第三方iOS App后的后续处理工作
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation {
return [self handleOpenURL:url sourceApplication:sourceApplication];
}
- (BOOL)handleOpenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication {
return [WWKApi handleOpenURL:url delegate:self];
}
3.现在,你的程序要实现和企业微信终端交互的具体请求与回应,因此需要实现WWKApiDelegate协议的两个方法。第三方iOS App可以根据自身需求实现这两个方法
// 如果第三方程序向企业微信发送了sendReq的请求,那么onResp会被回调。sendReq请求调用后,会切到企业微信终端程序界面。
- (void)onResp:(WWKBaseResp *)resp {
}
// onReq是企业微信终端向第三方程序发起请求,要求第三方程序响应。第三方程序响应完后必须调用sendRsp返回。在调用sendRsp返回时,会切回到企业微信终端程序界面。
-(void) onReq:(WWKBaseReq*)req {
}
具体在此两方法中所要完成的内容由你定义,具体可参考企业微信开发工具包中的SDK Sample Demo源码。
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageTextAttachment *attachment = [[WWKMessageTextAttachment alloc] init];
attachment.text = @"惊天魔盗团2 / 三人行 / 独立日2 IMAX特惠票来袭,仅需40元不补差看巨幕3D影片,全城最低,等你来团"; // 示例用文字,请填写你想分享的实际文字内容
req.attachment = attachment;
[WWKApi sendReq:req];
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageFileAttachment *attachment = [[WWKMessageFileAttachment alloc] init];
// 示例用文件,请填写你想分享的实际文件路径和名称
attachment.filename = @"Download.pdf";
attachment.path = [[NSBundle mainBundle] pathForResource:@"About Downloads" ofType:@"pdf"];
req.attachment = attachment;
[WWKApi sendReq:req];
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];
// 示例用图片,请填写你想分享的实际图片路径和名称
attachment.filename = @"test.gif";
attachment.path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
req.attachment = attachment;
[WWKApi sendReq:req];
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageVideoAttachment *attachment = [[WWKMessageVideoAttachment alloc] init];
// 示例用小视频,请填写你想分享的实际小视频路径和名称
attachment.filename = @"video.mp4";
attachment.path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
req.attachment = attachment;
[WWKApi sendReq:req];
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageLinkAttachment *attachment = [[WWKMessageLinkAttachment alloc] init];
// 示例用链接,请填写你想分享的实际链接的标题、介绍、图标和URL
attachment.title = @"链接标题";
attachment.summary = @"链接介绍";
attachment.url = @"http://www.tencent.com";
attachment.icon = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"]];
req.attachment = attachment;
[WWKApi sendReq:req];
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageGroupAttachment *attachment = [[WWKMessageGroupAttachment alloc] init];
attachment.title = @"XXX的聊天记录";
NSMutableArray *array = [NSMutableArray array];
// 需要转发的内容可以通过addObject进行添加
// 可以一次性的添加不同类型的聊天记录
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小明";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-1000];
wrapper.avatarUrl = @"http://p.qlogo.cn/bizmail/BDHWBviaRjEgxSn7E5dBwXMM0bibQVVFXe6C6dhtAdsGMu7vL7AuNpIQ/100";
wrapper.attachment = ({
WWKMessageTextAttachment *text = [[WWKMessageTextAttachment alloc] init];
text.text = @"关注你我健康";
text;
});
wrapper;
})];
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小明";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-950];
wrapper.avatarUrl = @"http://p.qlogo.cn/bizmail/BDHWBviaRjEgxSn7E5dBwXMM0bibQVVFXe6C6dhtAdsGMu7vL7AuNpIQ/100";
wrapper.attachment = ({
WWKMessageImageAttachment *image = [[WWKMessageImageAttachment alloc] init];
image.filename = @"test.gif";
image.path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
image;
});
wrapper;
})];
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小明";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-930];
wrapper.avatarUrl = @"http://p.qlogo.cn/bizmail/BDHWBviaRjEgxSn7E5dBwXMM0bibQVVFXe6C6dhtAdsGMu7vL7AuNpIQ/100";
wrapper.attachment = ({
WWKMessageLocationAttachment *loc = [[WWKMessageLocationAttachment alloc] init];
loc.title = @"T.I.T创意园";
loc.address = @"广东省广州市海珠区新港中路397号";
loc.lat = 23.098837;
loc.lng = 113.325119;
loc;
});
wrapper;
})];
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小码";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-900];
wrapper.avatarData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"]];
wrapper.attachment = ({
WWKMessageTextAttachment *text = [[WWKMessageTextAttachment alloc] init];
text.text = @"学车找我不愁";
text;
});
wrapper;
})];
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小码";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-850];
wrapper.avatarData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"]];
wrapper.attachment = ({
WWKMessageFileAttachment *file = [[WWKMessageFileAttachment alloc] init];
file.filename = @"Download.pdf";
file.path = [[NSBundle mainBundle] pathForResource:@"About Downloads" ofType:@"pdf"];
file;
});
wrapper;
})];
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小码";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-850];
wrapper.avatarData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"]];
wrapper.attachment = ({
WWKMessageVideoAttachment *video = [[WWKMessageVideoAttachment alloc] init];
video.filename = @"video.mp4";
video.path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
video;
});
wrapper;
})];
[array addObject:({
WWKMessageAttachmentWrapper *wrapper = [[WWKMessageAttachmentWrapper alloc] init];
wrapper.name = @"小码";
wrapper.date = [[NSDate date] dateByAddingTimeInterval:-800];
wrapper.avatarData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"]];
wrapper.attachment = ({
WWKMessageLinkAttachment *link = [[WWKMessageLinkAttachment alloc] init];
link.title = @"链接标题";
link.summary = @"链接介绍";
link.url = @"http://www.tencent.com";
link.icon = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"]];
link;
});
wrapper;
})];
attachment.contents = array;
req.attachment = attachment;
[WWKApi sendReq:req];
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
// 示例用小程序,请填写应用关联的小程序username、路径和图片以及标题
attachment.userName = @"gh_xxxxxxxxxxxx@app"; //必须是应用关联的小程序,注意要有@app后缀
attachment.path = @"pages/index/index.html";
attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);
attachment.title = @"分享标题";
req.attachment = attachment;
[WWKApi sendReq:req];