Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonzhu committed Dec 9, 2016
0 parents commit 4a4d933
Show file tree
Hide file tree
Showing 342 changed files with 26,053 additions and 0 deletions.
42 changes: 42 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Tencent is pleased to support the open source community by making WeDemo available.
Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
If you have downloaded a copy of the WeDemo binary from Tencent, please note that the WeDemo binary is licensed under the MIT License.
If you have downloaded a copy of the WeDemo source code from Tencent, please note that WeDemo source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of WeDemo into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within WeDemo.
A copy of the MIT License is included in this file.
Other dependencies and licenses:

Open Source Software Licensed under the BSD 3-Clause License:
--------------------------------------------------------------------
1. Objective-C-RSA 1.0
Copyright (c) 2013 Objective-C-RSA(https://github.com/ideawu/Objective-C-RSA) Authors
All rights reserved.


Terms of the BSD 3-Clause License:
--------------------------------------------------------------------

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of [copyright holder] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



Open Source Software Licensed Under the MIT License:
--------------------------------------------------------------------
1. AFNetworking 3.0
Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/)

2. JFOpenWeatherMapManager 1.0
Copyright (c) 2013 Jonathan Field


Terms of the MIT License:
--------------------------------------------------------------------

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#WeChat AuthSDK Demo App

微信登录Demo为微信团队开源项目,用于微信开发者进行微信登录、分享功能开发时的参考Demo。微信开发者可以参考项目中的代码来开发应用,也可以直接使用项目中的代码到自己的App中。

开发者可以自由使用并传播本代码,但需要保留原作者信息。

联系我们:[email protected]

##Document

详见Wiki:

* [微信AuthDemoApp交互时序说明文档](https://github.com/Tencent/WeDemo/wiki/微信Auth-Demo-App交互时序说明文档)

* [WeChatAuthDemo客户端接入指南](https://github.com/Tencent/WeDemo/wiki/WeChatAuthDemo客户端接入指南)

* [WeChatAuthDemo生成密钥与自签名证书指南](https://github.com/Tencent/WeDemo/wiki/WeChatAuthDemo生成密钥与自签名证书指南)

* [WeChatAuthDemo后台(PHP)接入指南](https://github.com/Tencent/WeDemo/wiki/WeChatAuthDemo后台(PHP)接入指南)

##License
Copyright (c) 2015 Tencent

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



123 changes: 123 additions & 0 deletions doc/App_Integration_Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<h1 align='center'>WeChatAuthDemo客户端接入指南</h1>

##目录

* [概要]()
* [获取源代码]()
* [修改客户端AppInfo]()
* [修改AppId和AppDescription]()
* [修改Bundle Id]()
* [修改服务器信息]()
* [替换服务器地址]()
* [替换服务器RSA公钥和自签名SSL证书]()
* [编写新的功能]()
* [增加CGI配置]()
* [编写你自己的Engine]()

##概要
WeChatAuthDemo除了具有演示客户端,服务器如何安全的接入微信服务的作用,还提供了一套[安全的通信方式](https://github.com/Tencent/WeDemo/wiki/微信Auth-Demo-App交互时序说明文档)供开发者使用以快速搭建自己的App。本文为客户端接入指南,PHP端接入指南详见[WeChatAuthDemo后台(PHP)接入指南]()

##获取源代码
在Mac OS X上打开终端模拟器,输入以下命令:

```bash
cd your/favourite/folder
git clone https://github.com/Tencent/WeDemo
```

##修改客户端AppInfo

为了让客户端能成功拉起微信,发送你自己的App信息请求,并从微信中跳转回来,需要修改客户端提供AppId等信息。具体修改步骤如下:

###修改AppId和AppDescription

在终端模拟器中输入以下命令来打开工程所在目录:

```bash
cd WeDemo/iOS/wechatauthdemo
open .
```

在弹出的Finder窗口中打开工程文件```wechatauthdemo.xcworkspace```。在工程树中找到并修改**Info.plist**中的App信息,如下图所示:

![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/WXAppInfo.jpg)

将图中的WXAppInfo中的AppId和AppDescription的值修改为你在[https://open.weixin.qq.com](https://open.weixin.qq.com)上注册的App信息,否则将无法在应用程序启动时向微信注册。

同时将图中的URL types中的URL identifier改为你的应用名,URL Schemes改为你的AppId,否则微信将无法跳转回你的应用。

###修改Bundle Id

在工程树设置文件中找到Bundle Indentifier的值修改为你在[https://open.weixin.qq.com](https://open.weixin.qq.com)上登记的Bundle Id,如下图所示:

![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/BundleId.jpg)

##修改服务器信息

为了让你自己的服务器能成功接收到请求并做出响应,需要替换客户端中的服务器信息,具体步骤如下:

###替换服务器地址
找到[BaseNetworkEngine.m](https://github.com/weixin-open/WeChatAuthDemo/blob/master/iOS/wechatauthdemo/Service/BaseNetworkEngine.m)文件,修改defaultHost的值为你自己的服务器地址,如下图所示:

![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/defaultHost.jpg)

###替换服务器RSA公钥和自签名SSL证书

将服务器中用于与App通信的RSA公钥和SSL证书下载下来, 然后打开[BaseNetworkEngine.m](https://github.com/weixin-open/WeChatAuthDemo/blob/master/iOS/wechatauthdemo/Service/BaseNetworkEngine.m)文件,将公钥内容复制替换掉,如下图所示:

![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/RSAPublicKey.jpg)

**注意,我们这里强烈建议使用2048位以上的钥匙对,具体生成密钥指南详见[WeChatAuthDemo生成RSA钥匙对与自签名证书指南](https://github.com/Tencent/WeDemo/wiki/WeChatAuthDemo生成密钥与自签名证书指南)**

接下来将原来的工程的Bundle Resource中的SSL证书替换成你自己的自签名证书,如下图所示:

![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/serverCer.jpg)

##编写新的功能
你可以在WeChatAuthDemo的基础上添加你自己的功能,完成你的App。

###增加CGI配置
按照[ConfigItemsMaker.h](https://github.com/Tencent/WeDemo/blob/master/iOS/wechatauthdemo/Service/ConfigItemsMaker.h)的格式,增加你需要增加的CGI的配置信息,包括请求的路径,加解密算法等,参考示例如下(在[ConfigItemsMaker.h](https://github.com/Tencent/WeDemo/blob/master/iOS/wechatauthdemo/Service/ConfigItemsMaker.h)):

```objective-c
@{
@"cgi_name": @"appcgi_replylist", //这个配置的ID
@"request_path": @"/wxoauth/demo/index.php?action=replylist", //请求路径
@"http_method": @"POST", //HTTP方法
@"encrypt_algorithm": @"6", //加密算法
@"decrypt_algorithm": @"6", //解密算法
@"encrypt_key_path": @"req_buffer", //加密的结构
@"decrypt_key_path": @"resp_buffer", //解密的结构
@"sys_err_key_path": @"errcode" //错误码的Key
}
```

###编写你自己的Engine
之后只需要继承[BaseNetworkEngine](https://github.com/Tencent/WeDemo/blob/master/iOS/wechatauthdemo/Service/BaseNetworkEngine.m),然后用```JSONTaskForHost:Para:ConfigKeyPath:WithCompletion:```建立一个网络请求并发起即可,参考示例如下(在[ADNetworkEngine.m](https://github.com/Tencent/WeDemo/blob/master/iOS/wechatauthdemo/Service/ADNetworkEngine.m)中):

```objective-c
- (void)getReplyListForUin:(UInt32)uin
OfComment:(NSString *)commentId
WithCompletion:(GetReplyListCallBack)completion {
[[self.manager JSONTaskForHost:self.host
Para:@{
@"uin": @(uin),
@"req_buffer": @{
@"uin": @(uin),
@"comment_id": commentId
}
}
ConfigKeyPath: @"appcgi_replylist"
WithCompletion:^(NSDictionary *dict, NSError *error) {
//处理网络回调
}] resume];
}
```

###调试

WeChatAuthDemo在Debug模式下还在首页提供了一个可以修改CGI配置的调试页面,同时还在App全局提供摇一摇手势呼出日志窗口,你还可以在他们上面集成其它调试工具如[FLEX](https://github.com/Flipboard/FLEX)等, enjoy! **:-)**

![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/Index.jpg)|![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/Debug.jpg)
-------|-------
![](https://raw.githubusercontent.com/Tencent/WeDemo/master/doc/image/Log.jpg)|
Loading

0 comments on commit 4a4d933

Please sign in to comment.