Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Cpprestsdk | 7,574 | 145 | 10 | 10 days ago | 25 | January 01, 1900 | 833 | other | C++ | |
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services. | ||||||||||
Octokit.js | 6,412 | 26 | 315 | 3 days ago | 79 | July 26, 2023 | 24 | mit | TypeScript | |
The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno. | ||||||||||
4,331 | 47 | 5 days ago | 64 | June 30, 2023 | 97 | apache-2.0 | Go | |||
WeChat SDK for Go (微信SDK:简单、易用) | ||||||||||
Octokit.rb | 3,791 | 36,226 | 686 | a day ago | 134 | July 28, 2023 | 23 | mit | Ruby | |
Ruby toolkit for the GitHub API | ||||||||||
Openshare | 3,630 | 5 years ago | 1 | October 09, 2017 | 92 | gpl-3.0 | Objective-C | |||
不用官方SDK,利用社交软件移动客户端(微信/QQ/微博/人人/支付宝)分享/登录/支付。 | ||||||||||
Laravel Wechat | 2,809 | 345 | 57 | 5 months ago | 72 | October 17, 2022 | 1 | mit | PHP | |
微信 SDK for Laravel, 基于 overtrue/wechat | ||||||||||
Fosite | 2,145 | 50 | 88 | 8 days ago | 280 | December 07, 2022 | 39 | apache-2.0 | Go | |
Extensible security first OAuth 2.0 and OpenID Connect SDK for Go. | ||||||||||
Macassistant | 1,592 | 7 months ago | 32 | mit | Swift | |||||
Google Assistant for macOS! | ||||||||||
Auth0.js | 950 | 6,666 | 328 | 4 days ago | 253 | July 19, 2023 | 1 | mit | JavaScript | |
Auth0 headless browser sdk | ||||||||||
Dropbox Sdk Python | 875 | 1,086 | 77 | a month ago | 134 | June 15, 2022 | 39 | mit | Python | |
The Official Dropbox API V2 SDK for Python |
OpenShare 的功能就是替代官方的 SDK 向各个平台的移动客户端(比如 QQ)发起请求(分享、OAuth),然后接收返回结果。
OpenShare 非常小,目前支持 QQ、微信、微博、人人,只有几百行代码。即使你不在项目中使用 OpenShare,也可以 clone 下来研究一下 App 和客户端之间的通信机制,所以给个 star 是值得的。
注:为方便书写,如无特殊说明,下文中的「客户端」指的是 QQ、微信、微博这样的社交软件官方开发的客户端;「App」特指我们自己开发的应用。
把项目 clone 下来以后,直接 open OpenShareDemo/openshare.xcodeproj
就可以运行了。注意 sina 微博的 key 没有通过 sina 的审核,直接分享会提示错误,可以替换成自己的 key。
楼主做 iOS 开发的过程中遇到这样的问题:自己 App 中的信息需要分享到 QQ、微信、微博等社交网络。现在的客户端越做越强大,直接集成了分享功能,比如用户手机上安装了微信,只需要 App 调起微信,并且给微信传入相应的参数就可以了,完全不需要自己操作 REST API。这样如果实现分享,一般情况下要去官方下载 SDK,然后按照官方翔一样的 Demo 代码和文档来改造自己的程序。这样做不仅增大了代码量(想象一下引入的官方类库,有时候,光这些第三方的 SDK 都要比我自己的 App 还大),而且使用还很繁琐(SDK 一般没有源代码,想象 Apple 强制 App 支持 64 位的时候)。所以楼主调试了一下各个平台的 SDK,研究了各个厂商实现的应用程序间通信的规则,把功能封装成了 OpenShare。
比如分享功能,OpenShare 有一个 OSMessage 类,保存 OpenShare 向客户端发送的消息。分享的消息基本上有以下几种情况:
这样对应 OSMessage 中的属性:
@property NSString* title;
@property NSString* desc;
@property NSString* link;
@property NSData* image;
@property NSData* thumbnail;
@property OSMultimediaType multimediaType;
// for 微信
@property NSString* extInfo;
@property NSString* mediaDataUrl;
@property NSString* fileExt;
比如一个文本消息,可以只设置 title,其他不管;发送一个图片,只需要设置 image / thumbnail / title / desc,其他不用设置。对于其他多媒体消息,可以用 multimediaType 来标示。所以 OSMessage 可以封装所有 App 向客户端发的各类分享请求。
另外,还需要解决的是,客户端分享完成以后回调 App 的功能。我们熟悉的是 block 方法。而不是每个平台都到 application:openURL:sourceApplication:annotation: 中判断。比如最好是这样的:
OSMessage *msg=[[OSMessage alloc] init];
msg.title=@"Hello World";
// 分享到微信
[OpenShare shareToWeixinSession:msg Success:^(OSMessage *message) {
ULog(@"微信分享到会话成功:\n%@",message);
} Fail:^(OSMessage *message, NSError *error) {
ULog(@"微信分享到会话失败:\n%@\n%@",error,message);
}];
// 分享到QQ
[OpenShare shareToQQFriends:msg Success:^(OSMessage *message) {
ULog(@"分享到QQ好友成功:%@",msg);
} Fail:^(OSMessage *message, NSError *error) {
ULog(@"分享到QQ好友失败:%@\n%@",msg,error);
}];
基于以上考虑,楼主用 category 实现了 OpenShare。
OpenShare 已经支持 CocoaPods。所以您可以用:
pod 'OpenShare'
引入 OpenShare。
第零步: 修改 Info.plist
添加 URLSchemes
,让客户端可以回调 App:
<!-- OpenShare添加回调urlschemes -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>OpenShare</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- 微信 -->
<string>wxd930ea5d5a258f4f</string>
<!-- QQ -->
<string>tencent1103194207</string>
<string>tencent1103194207.content</string>
<string>QQ41C1685F</string>
<!--微博-->
<string>wb402180334</string>
<!--人人-->
<string>renrenshare228525</string>
<!--facebook-->
<string>fb776442542471056</string>
</array>
</dict>
</array>
第一步:到 AppDelegate
中的 application:didFinishLaunchingWithOptions:
中全局注册 AppId / AppKey:
// 全局注册appId,别忘了#import "OpenShareHeader.h"
[OpenShare connectQQWithAppId:@"1103194207"];
[OpenShare connectWeiboWithAppKey:@"402180334"];
[OpenShare connectWeixinWithAppId:@"wxd930ea5d5a258f4f"];
[OpenShare connectRenrenWithAppId:@"228525" AndAppKey:@"1dd8cba4215d4d4ab96a49d3058c1d7f"];
第二步:到AppDelegate中
的application:openURL:sourceApplication:annotation:
中添加整体回调:
// 如果OpenShare能处理这个回调,就调用block中的方法,如果不能处理,就交给其他(比如支付宝)。
if ([OpenShare handleOpenURL:url]) {
return YES;
}
第三步:在需要分享、OAuth 的地方调用:
// 比如微信登录,其他登录可以参考文档或者代码,或者让Xcode自动提示。
[OpenShare WeixinAuth:@"snsapi_userinfo" Success:^(NSDictionary *message) {
ULog(@"微信登录成功:\n%@",message);
} Fail:^(NSDictionary *message, NSError *error) {
ULog(@"微信登录失败:\n%@\n%@",message,error);
}];
//分享纯文本消息到微信朋友圈,其他类型可以参考示例代码
OSMessage *msg=[[OSMessage alloc]init];
msg.title=@"Hello msg.title";
[OpenShare shareToWeixinTimeline:msg Success:^(OSMessage *message) {
ULog(@"微信分享到朋友圈成功:\n%@",message);
} Fail:^(OSMessage *message, NSError *error) {
ULog(@"微信分享到朋友圈失败:\n%@\n%@",error,message);
}];
现在的社交网络各种各样,如何把这些平台集成到 OpenShare 中呢?就像插件一样,可以把自己实现的 OpenShare+foobar.h
和 OpenShare+foobar.m
添加进来就可以了。这里 提供了一个模板工具,只需要输入你想扩展的平台的名称,就会自动生成 .h
和 .m
文件,然后基于这个模板修改即可。
由于每个厂商的通信协议都不一样,所以 hack 的时候还是走了一些弯路,如果想了解整个实现过程,可以看看我的博客:http://www.gfzj.us/series/openshare/
现在行业急需要像 OAuth 一样的标准,来实现 App 和客户端之间的分享,登录。这样就不用为每一个客户端实现一遍了。比如这个协议标准就叫做「OpenShare」(大言不惭、捂脸中)。客户端只需要声明支持 OpenShare 的某个版本,App 就能很简单的调用了。如果您对实现 OpenShare 标准有任何想法,欢迎交流。
在 OpenShare 使用过程中有任何问题,都可以添加一个 issues,我会及时解决。如果您想贡献代码,欢迎 Pull Requests。其他任何问题可以在下面留言,或者通过邮箱 [email protected] 联系我。
OpenShare 基于 GPLv3 协议进行分发和使用,更多信息参见协议文件。