├── .gitignore ├── README.md ├── WXApi.h ├── WXApiObject.h ├── WechatAuthSDK.h ├── libWeChatSDK.a └── libWeChatSDK.podspec /.gitignore: -------------------------------------------------------------------------------- 1 | # CocoaPods 2 | # 3 | # We recommend against adding the Pods directory to your .gitignore. However 4 | # you should judge for yourself, the pros and cons are mentioned at: 5 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control? 6 | # 7 | # Pods/ 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libWeChatSDK 2 | 3 | Mirror for CocoaPods 4 | 5 | 官方下载地址: 6 | [`https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/WeChatSDK1.7.5.zip`](https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/WeChatSDK1.7.5.zip) 7 | 8 | # SDK 1.7.5 9 | 10 | 1. 提高稳定性 11 | 2. 加快 `registerApp` 接口启动速度 12 | 13 | # SDK 1.7.4 14 | 15 | 1. 更新支持 iOS 启用 ATS(App Transport Security) 16 | 2. 需要在工程中链接 `CFNetwork.framework` 17 | 3. 在工程配置中的 `Other Linker Flags` 中加入 `-Objc -all_load` 18 | 19 | # SDK 1.7.3 20 | 21 | 1. 增强稳定性,适配 iOS10 22 | 2. 修复小于 32K 的 jpg 格式缩略图设置失败的问题 23 | 24 | # SDK 1.7.2 25 | 26 | 1. 修复因 `CTTeleponyNetworkInfo` 引起的崩溃问题 27 | 28 | # SDK 1.7.1 29 | 30 | 1. 支持兼容 ipv6 (提升稳定性) 31 | 2. xCode Version 7.3.1 (7D1014) 编译 32 | 33 | # SDK 1.7 34 | 35 | 1. 支持兼容 ipv6 36 | 2. 修复若干问题增强稳定性 37 | 38 | # SDK 1.6.2 39 | 40 | 1. Xcode 7.1 构建的 SDK 包 41 | 2. 请使用 Xcode 7.1 进行编译 42 | 43 | # SDK 1.6.1 44 | 45 | 1. 修复 armv7s 下, bitcode 可能编译不过 46 | 2. 解决 warning 47 | 48 | # SDK 1.6 49 | 50 | 1. iOS 9 系统策略更新,限制了 HTTP 协议的访问,此外应用需要在 `Info.plist` 中将要使用的 URL Schemes 列为白名单,才可正常检查其他应用是否安装。 51 | 受此影响,当你的应用在 iOS 9 中需要使用微信 SDK 的相关能力(分享、收藏、支付、登录等)时,需要在 `Info.plist` 里增加如下代码: 52 | 53 | ```xml 54 | LSApplicationQueriesSchemes 55 | 56 | weixin 57 | 58 | 59 | NSAppTransportSecurity 60 | 61 | NSAllowsArbitraryLoads 62 | 63 | 64 | ``` 65 | 66 | 或者配置白名单域名 `pingma.qq.com` 67 | 68 | 2. 开发者需要在工程中链接上 `CoreTelephony.framework` 69 | 3. 解决 bitcode 编译不过问题 70 | 71 | # SDK 1.5 72 | 73 | 1. 废弃 `safeSendReq:` 接口,使用 `sendReq:` 即可。 74 | 2. 新增 `+(BOOL) sendAuthReq:(SendAuthReq*) req viewController : (UIViewController*) viewController delegate:(id) delegate;` 75 | 支持未安装微信情况下Auth,具体见 `WXApi.h` 接口描述 76 | 3. 微信开放平台新增了微信模块用户统计功能,便于开发者统计微信功能模块的用户使用和活跃情况。开发者需要在工程中链接上: `SystemConfiguration.framework`, `libz.dylib`, `libsqlite3.0.dylib`。 77 | -------------------------------------------------------------------------------- /WXApi.h: -------------------------------------------------------------------------------- 1 | // 2 | // WXApi.h 3 | // 所有Api接口 4 | // 5 | // Created by Wechat on 12-2-28. 6 | // Copyright (c) 2012年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WXApiObject.h" 11 | 12 | 13 | #pragma mark - WXApiDelegate 14 | /*! @brief 接收并处理来自微信终端程序的事件消息 15 | * 16 | * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 17 | * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 18 | */ 19 | @protocol WXApiDelegate 20 | @optional 21 | 22 | /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 23 | * 24 | * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 25 | * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 26 | * @param req 具体请求内容,是自动释放的 27 | */ 28 | -(void) onReq:(BaseReq*)req; 29 | 30 | 31 | 32 | /*! @brief 发送一个sendReq后,收到微信的回应 33 | * 34 | * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 35 | * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 36 | * @param resp具体的回应内容,是自动释放的 37 | */ 38 | -(void) onResp:(BaseResp*)resp; 39 | 40 | @end 41 | 42 | 43 | 44 | #pragma mark - WXApi 45 | 46 | /*! @brief 微信Api接口函数类 47 | * 48 | * 该类封装了微信终端SDK的所有接口 49 | */ 50 | @interface WXApi : NSObject 51 | 52 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 53 | * 54 | * 需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现。 55 | * iOS7及以上系统需要调起一次微信才会出现在微信的可用应用列表中。 56 | * @attention 请保证在主线程中调用此函数 57 | * @param appid 微信开发者ID 58 | * @param typeFlag 应用支持打开的文件类型 59 | * @return 成功返回YES,失败返回NO。 60 | */ 61 | +(BOOL) registerApp:(NSString *)appid; 62 | 63 | 64 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 65 | * 66 | * 需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现。 67 | * @see registerApp 68 | * @param appid 微信开发者ID 69 | * @param appdesc 应用附加信息,长度不超过1024字节 70 | * @return 成功返回YES,失败返回NO。 71 | */ 72 | +(BOOL) registerApp:(NSString *)appid withDescription:(NSString *)appdesc; 73 | 74 | 75 | /*! @brief WXApi的成员函数,向微信终端程序注册应用支持打开的文件类型。 76 | * 77 | * 需要在每次启动第三方应用程序时调用。调用后并第一次成功分享数据到微信后,会在微信的可用应用列表中出现。 78 | * @see registerApp 79 | * @param typeFlag 应用支持打开的数据类型, enAppSupportContentFlag枚举类型 “|” 操作后结果 80 | */ 81 | +(void) registerAppSupportContentFlag:(UInt64)typeFlag; 82 | 83 | 84 | 85 | /*! @brief 处理微信通过URL启动App时传递的数据 86 | * 87 | * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 88 | * @param url 微信启动第三方应用时传递过来的URL 89 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 90 | * @return 成功返回YES,失败返回NO。 91 | */ 92 | +(BOOL) handleOpenURL:(NSURL *) url delegate:(id) delegate; 93 | 94 | 95 | 96 | /*! @brief 检查微信是否已被用户安装 97 | * 98 | * @return 微信已安装返回YES,未安装返回NO。 99 | */ 100 | +(BOOL) isWXAppInstalled; 101 | 102 | 103 | 104 | /*! @brief 判断当前微信的版本是否支持OpenApi 105 | * 106 | * @return 支持返回YES,不支持返回NO。 107 | */ 108 | +(BOOL) isWXAppSupportApi; 109 | 110 | 111 | 112 | /*! @brief 获取微信的itunes安装地址 113 | * 114 | * @return 微信的安装地址字符串。 115 | */ 116 | +(NSString *) getWXAppInstallUrl; 117 | 118 | 119 | 120 | /*! @brief 获取当前微信SDK的版本号 121 | * 122 | * @return 返回当前微信SDK的版本号 123 | */ 124 | +(NSString *) getApiVersion; 125 | 126 | 127 | 128 | /*! @brief 打开微信 129 | * 130 | * @return 成功返回YES,失败返回NO。 131 | */ 132 | +(BOOL) openWXApp; 133 | 134 | 135 | 136 | /*! @brief 发送请求到微信,等待微信返回onResp 137 | * 138 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 139 | * SendAuthReq、SendMessageToWXReq、PayReq等。 140 | * @param req 具体的发送请求,在调用函数后,请自己释放。 141 | * @return 成功返回YES,失败返回NO。 142 | */ 143 | +(BOOL) sendReq:(BaseReq*)req; 144 | 145 | /*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp 146 | * 147 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 148 | * @param req 具体的发送请求,在调用函数后,请自己释放。 149 | * @param viewController 当前界面对象。 150 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 151 | * @return 成功返回YES,失败返回NO。 152 | */ 153 | +(BOOL) sendAuthReq:(SendAuthReq*)req viewController:(UIViewController*)viewController delegate:(id)delegate; 154 | 155 | 156 | /*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 157 | * 158 | * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 159 | * GetMessageFromWXResp、ShowMessageFromWXResp等。 160 | * @param resp 具体的应答内容,调用函数后,请自己释放 161 | * @return 成功返回YES,失败返回NO。 162 | */ 163 | +(BOOL) sendResp:(BaseResp*)resp; 164 | 165 | 166 | @end 167 | -------------------------------------------------------------------------------- /WXApiObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // MMApiObject.h 3 | // Api对象,包含所有接口和对象数据定义 4 | // 5 | // Created by Wechat on 12-2-28. 6 | // Copyright (c) 2012年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! @brief 错误码 12 | * 13 | */ 14 | enum WXErrCode { 15 | WXSuccess = 0, /**< 成功 */ 16 | WXErrCodeCommon = -1, /**< 普通错误类型 */ 17 | WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ 18 | WXErrCodeSentFail = -3, /**< 发送失败 */ 19 | WXErrCodeAuthDeny = -4, /**< 授权失败 */ 20 | WXErrCodeUnsupport = -5, /**< 微信不支持 */ 21 | }; 22 | 23 | 24 | 25 | /*! @brief 请求发送场景 26 | * 27 | */ 28 | enum WXScene { 29 | WXSceneSession = 0, /**< 聊天界面 */ 30 | WXSceneTimeline = 1, /**< 朋友圈 */ 31 | WXSceneFavorite = 2, /**< 收藏 */ 32 | }; 33 | 34 | 35 | 36 | enum WXAPISupport { 37 | WXAPISupportSession = 0, 38 | }; 39 | 40 | 41 | 42 | /*! @brief 跳转profile类型 43 | * 44 | */ 45 | enum WXBizProfileType{ 46 | WXBizProfileType_Normal = 0, //**< 普通公众号 */ 47 | WXBizProfileType_Device = 1, //**< 硬件公众号 */ 48 | }; 49 | 50 | 51 | 52 | /*! @brief 跳转mp网页类型 53 | * 54 | */ 55 | enum WXMPWebviewType { 56 | WXMPWebviewType_Ad = 0, /**< 广告网页 **/ 57 | }; 58 | 59 | 60 | /*! @brief 应用支持接收微信的文件类型 61 | * 62 | */ 63 | typedef NS_ENUM(UInt64, enAppSupportContentFlag) 64 | { 65 | MMAPP_SUPPORT_NOCONTENT = 0x0, 66 | MMAPP_SUPPORT_TEXT = 0x1, 67 | MMAPP_SUPPORT_PICTURE = 0x2, 68 | MMAPP_SUPPORT_LOCATION = 0x4, 69 | MMAPP_SUPPORT_VIDEO = 0x8, 70 | MMAPP_SUPPORT_AUDIO = 0x10, 71 | MMAPP_SUPPORT_WEBPAGE = 0x20, 72 | 73 | // Suport File Type 74 | MMAPP_SUPPORT_DOC = 0x40, // doc 75 | MMAPP_SUPPORT_DOCX = 0x80, // docx 76 | MMAPP_SUPPORT_PPT = 0x100, // ppt 77 | MMAPP_SUPPORT_PPTX = 0x200, // pptx 78 | MMAPP_SUPPORT_XLS = 0x400, // xls 79 | MMAPP_SUPPORT_XLSX = 0x800, // xlsx 80 | MMAPP_SUPPORT_PDF = 0x1000, // pdf 81 | }; 82 | 83 | #pragma mark - BaseReq 84 | /*! @brief 该类为微信终端SDK所有请求类的基类 85 | * 86 | */ 87 | @interface BaseReq : NSObject 88 | 89 | /** 请求类型 */ 90 | @property (nonatomic, assign) int type; 91 | /** 由用户微信号和AppID组成的唯一标识,发送请求时第三方程序必须填写,用于校验微信用户是否换号登录*/ 92 | @property (nonatomic, retain) NSString* openID; 93 | 94 | @end 95 | 96 | 97 | 98 | #pragma mark - BaseResp 99 | /*! @brief 该类为微信终端SDK所有响应类的基类 100 | * 101 | */ 102 | @interface BaseResp : NSObject 103 | /** 错误码 */ 104 | @property (nonatomic, assign) int errCode; 105 | /** 错误提示字符串 */ 106 | @property (nonatomic, retain) NSString *errStr; 107 | /** 响应类型 */ 108 | @property (nonatomic, assign) int type; 109 | 110 | @end 111 | 112 | 113 | 114 | #pragma mark - WXMediaMessage 115 | @class WXMediaMessage; 116 | 117 | /*! @brief 第三方向微信终端发起支付的消息结构体 118 | * 119 | * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 120 | * @see PayResp 121 | */ 122 | @interface PayReq : BaseReq 123 | 124 | /** 商家向财付通申请的商家id */ 125 | @property (nonatomic, retain) NSString *partnerId; 126 | /** 预支付订单 */ 127 | @property (nonatomic, retain) NSString *prepayId; 128 | /** 随机串,防重发 */ 129 | @property (nonatomic, retain) NSString *nonceStr; 130 | /** 时间戳,防重发 */ 131 | @property (nonatomic, assign) UInt32 timeStamp; 132 | /** 商家根据财付通文档填写的数据和签名 */ 133 | @property (nonatomic, retain) NSString *package; 134 | /** 商家根据微信开放平台文档对数据做的签名 */ 135 | @property (nonatomic, retain) NSString *sign; 136 | 137 | @end 138 | 139 | 140 | 141 | #pragma mark - PayResp 142 | /*! @brief 微信终端返回给第三方的关于支付结果的结构体 143 | * 144 | * 微信终端返回给第三方的关于支付结果的结构体 145 | */ 146 | @interface PayResp : BaseResp 147 | 148 | /** 财付通返回给商家的信息 */ 149 | @property (nonatomic, retain) NSString *returnKey; 150 | 151 | @end 152 | 153 | 154 | 155 | /*! @brief 第三方向微信终端发起拆企业红包的消息结构体 156 | * 157 | * 第三方向微信终端发起拆企业红包的消息结构体,微信终端处理后会向第三方返回处理结果 158 | * @see HBReq 159 | */ 160 | @interface HBReq : BaseReq 161 | 162 | /** 随机串,防重发 */ 163 | @property (nonatomic, retain) NSString *nonceStr; 164 | /** 时间戳,防重发 */ 165 | @property (nonatomic, assign) UInt32 timeStamp; 166 | /** 商家根据微信企业红包开发文档填写的数据和签名 */ 167 | @property (nonatomic, retain) NSString *package; 168 | /** 商家根据微信企业红包开发文档对数据做的签名 */ 169 | @property (nonatomic, retain) NSString *sign; 170 | 171 | @end 172 | 173 | 174 | 175 | #pragma mark - HBResp 176 | /*! @brief 微信终端返回给第三方的关于拆企业红包结果的结构体 177 | * 178 | * 微信终端返回给第三方的关于拆企业红包结果的结构体 179 | */ 180 | @interface HBResp : BaseResp 181 | 182 | @end 183 | 184 | 185 | 186 | 187 | #pragma mark - SendAuthReq 188 | /*! @brief 第三方程序向微信终端请求认证的消息结构 189 | * 190 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, 191 | * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 192 | * @see SendAuthResp 193 | */ 194 | @interface SendAuthReq : BaseReq 195 | /** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 196 | * @see SendAuthResp 197 | * @note scope字符串长度不能超过1K 198 | */ 199 | @property (nonatomic, retain) NSString* scope; 200 | /** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 201 | * @note state字符串长度不能超过1K 202 | */ 203 | @property (nonatomic, retain) NSString* state; 204 | @end 205 | 206 | 207 | 208 | #pragma mark - SendAuthResp 209 | /*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 210 | * 211 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 212 | * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 213 | * @see onResp 214 | */ 215 | @interface SendAuthResp : BaseResp 216 | @property (nonatomic, retain) NSString* code; 217 | /** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 218 | * @note state字符串长度不能超过1K 219 | */ 220 | @property (nonatomic, retain) NSString* state; 221 | @property (nonatomic, retain) NSString* lang; 222 | @property (nonatomic, retain) NSString* country; 223 | @end 224 | 225 | 226 | 227 | #pragma mark - SendMessageToWXReq 228 | /*! @brief 第三方程序发送消息至微信终端程序的消息结构体 229 | * 230 | * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, 231 | * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 232 | * @see SendMessageToWXResp 233 | */ 234 | @interface SendMessageToWXReq : BaseReq 235 | /** 发送消息的文本内容 236 | * @note 文本长度必须大于0且小于10K 237 | */ 238 | @property (nonatomic, retain) NSString* text; 239 | /** 发送消息的多媒体内容 240 | * @see WXMediaMessage 241 | */ 242 | @property (nonatomic, retain) WXMediaMessage* message; 243 | /** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 244 | @property (nonatomic, assign) BOOL bText; 245 | /** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 246 | * @see WXScene 247 | */ 248 | @property (nonatomic, assign) int scene; 249 | 250 | @end 251 | 252 | 253 | 254 | #pragma mark - SendMessageToWXResp 255 | /*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 256 | * 257 | * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 258 | */ 259 | @interface SendMessageToWXResp : BaseResp 260 | @property(nonatomic, retain) NSString* lang; 261 | @property(nonatomic, retain) NSString* country; 262 | @end 263 | 264 | 265 | 266 | #pragma mark - GetMessageFromWXReq 267 | /*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 268 | * 269 | * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, 270 | * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 271 | */ 272 | @interface GetMessageFromWXReq : BaseReq 273 | @property (nonatomic, retain) NSString* lang; 274 | @property (nonatomic, retain) NSString* country; 275 | @end 276 | 277 | 278 | 279 | #pragma mark - GetMessageFromWXResp 280 | /*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 281 | * 282 | * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 283 | */ 284 | @interface GetMessageFromWXResp : BaseResp 285 | /** 向微信终端提供的文本内容 286 | @note 文本长度必须大于0且小于10K 287 | */ 288 | @property (nonatomic, retain) NSString* text; 289 | /** 向微信终端提供的多媒体内容。 290 | * @see WXMediaMessage 291 | */ 292 | @property (nonatomic, retain) WXMediaMessage* message; 293 | /** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 294 | @property (nonatomic, assign) BOOL bText; 295 | @end 296 | 297 | 298 | 299 | #pragma mark - ShowMessageFromWXReq 300 | /*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 301 | * 302 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 303 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 304 | */ 305 | @interface ShowMessageFromWXReq : BaseReq 306 | /** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 307 | * @see WXMediaMessage 308 | */ 309 | @property (nonatomic, retain) WXMediaMessage* message; 310 | @property (nonatomic, retain) NSString* lang; 311 | @property (nonatomic, retain) NSString* country; 312 | @end 313 | 314 | 315 | 316 | #pragma mark - ShowMessageFromWXResp 317 | /*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 318 | * 319 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 320 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 321 | */ 322 | @interface ShowMessageFromWXResp : BaseResp 323 | @end 324 | 325 | 326 | 327 | #pragma mark - LaunchFromWXReq 328 | /*! @brief 微信终端打开第三方程序携带的消息结构体 329 | * 330 | * 微信向第三方发送的结构体,第三方不需要返回 331 | */ 332 | @interface LaunchFromWXReq : BaseReq 333 | @property (nonatomic, retain) WXMediaMessage* message; 334 | @property (nonatomic, retain) NSString* lang; 335 | @property (nonatomic, retain) NSString* country; 336 | @end 337 | 338 | #pragma mark - OpenTempSessionReq 339 | /* ! @brief 第三方通知微信,打开临时会话 340 | * 341 | * 第三方通知微信,打开临时会话 342 | */ 343 | @interface OpenTempSessionReq : BaseReq 344 | /** 需要打开的用户名 345 | * @attention 长度不能超过512字节 346 | */ 347 | @property (nonatomic, retain) NSString* username; 348 | /** 开发者自定义参数,拉起临时会话后会发给开发者后台,可以用于识别场景 349 | * @attention 长度不能超过32位 350 | */ 351 | @property (nonatomic, retain) NSString* sessionFrom; 352 | @end 353 | 354 | #pragma mark - OpenWebviewReq 355 | /* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 356 | * 357 | * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 358 | */ 359 | @interface OpenWebviewReq : BaseReq 360 | /** 需要打开的网页对应的Url 361 | * @attention 长度不能超过1024 362 | */ 363 | @property(nonatomic,retain)NSString* url; 364 | 365 | @end 366 | 367 | #pragma mark - OpenWebviewResp 368 | /*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 369 | * 370 | * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 371 | */ 372 | @interface OpenWebviewResp : BaseResp 373 | 374 | @end 375 | 376 | 377 | #pragma mark - OpenTempSessionResp 378 | /*! @brief 微信终端向第三方程序返回的OpenTempSessionReq处理结果。 379 | * 380 | * 第三方程序向微信终端发送OpenTempSessionReq后,微信发送回来的处理结果,该结果用OpenTempSessionResp表示。 381 | */ 382 | @interface OpenTempSessionResp : BaseResp 383 | 384 | @end 385 | 386 | #pragma mark - OpenRankListReq 387 | /* ! @brief 第三方通知微信,打开硬件排行榜 388 | * 389 | * 第三方通知微信,打开硬件排行榜 390 | */ 391 | @interface OpenRankListReq : BaseReq 392 | 393 | @end 394 | 395 | #pragma mark - OpenRanklistResp 396 | /*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 397 | * 398 | * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 399 | */ 400 | @interface OpenRankListResp : BaseResp 401 | 402 | @end 403 | 404 | #pragma mark - JumpToBizProfileReq 405 | /* ! @brief 第三方通知微信,打开指定微信号profile页面 406 | * 407 | * 第三方通知微信,打开指定微信号profile页面 408 | */ 409 | @interface JumpToBizProfileReq : BaseReq 410 | /** 跳转到该公众号的profile 411 | * @attention 长度不能超过512字节 412 | */ 413 | @property (nonatomic, retain) NSString* username; 414 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 415 | * @attention 长度不能超过1024字节 416 | */ 417 | @property (nonatomic, retain) NSString* extMsg; 418 | /** 419 | * 跳转的公众号类型 420 | * @see WXBizProfileType 421 | */ 422 | @property (nonatomic, assign) int profileType; 423 | @end 424 | 425 | 426 | 427 | #pragma mark - JumpToBizWebviewReq 428 | /* ! @brief 第三方通知微信,打开指定usrname的profile网页版 429 | * 430 | */ 431 | @interface JumpToBizWebviewReq : BaseReq 432 | /** 跳转的网页类型,目前只支持广告页 433 | * @see WXMPWebviewType 434 | */ 435 | @property(nonatomic, assign) int webType; 436 | /** 跳转到该公众号的profile网页版 437 | * @attention 长度不能超过512字节 438 | */ 439 | @property(nonatomic, retain) NSString* tousrname; 440 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 441 | * @attention 长度不能超过1024字节 442 | */ 443 | @property(nonatomic, retain) NSString* extMsg; 444 | 445 | @end 446 | 447 | #pragma mark - WXCardItem 448 | 449 | @interface WXCardItem : NSObject 450 | /** 卡id 451 | * @attention 长度不能超过1024字节 452 | */ 453 | @property (nonatomic,retain) NSString* cardId; 454 | /** ext信息 455 | * @attention 长度不能超过2024字节 456 | */ 457 | @property (nonatomic,retain) NSString* extMsg; 458 | /** 459 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 460 | */ 461 | @property (nonatomic,assign) UInt32 cardState; 462 | /** 463 | * @attention req不需要填,chooseCard返回的。 464 | */ 465 | @property (nonatomic,retain) NSString* encryptCode; 466 | /** 467 | * @attention req不需要填,chooseCard返回的。 468 | */ 469 | @property (nonatomic,retain) NSString* appID; 470 | @end; 471 | 472 | #pragma mark - AddCardToWXCardPackageReq 473 | /* ! @brief 请求添加卡券至微信卡包 474 | * 475 | */ 476 | 477 | @interface AddCardToWXCardPackageReq : BaseReq 478 | /** 卡列表 479 | * @attention 个数不能超过40个 类型WXCardItem 480 | */ 481 | @property (nonatomic,retain) NSArray* cardAry; 482 | 483 | @end 484 | 485 | 486 | #pragma mark - AddCardToWXCardPackageResp 487 | /** ! @brief 微信返回第三方添加卡券结果 488 | * 489 | */ 490 | 491 | @interface AddCardToWXCardPackageResp : BaseResp 492 | /** 卡列表 493 | * @attention 个数不能超过40个 类型WXCardItem 494 | */ 495 | @property (nonatomic,retain) NSArray* cardAry; 496 | @end 497 | 498 | #pragma mark - WXChooseCardReq 499 | /* ! @brief 请求从微信选取卡券 500 | * 501 | */ 502 | 503 | @interface WXChooseCardReq : BaseReq 504 | @property(nonatomic, strong) NSString *appID; 505 | @property(nonatomic, assign) UInt32 shopID; 506 | @property(nonatomic, assign) UInt32 canMultiSelect; 507 | @property(nonatomic, strong) NSString *cardType; 508 | @property(nonatomic, strong) NSString *cardTpID; 509 | @property(nonatomic, strong) NSString *signType; 510 | @property(nonatomic, strong) NSString *cardSign; 511 | @property(nonatomic, assign) UInt32 timeStamp; 512 | @property(nonatomic, strong) NSString *nonceStr; 513 | @end 514 | 515 | 516 | #pragma mark - WXChooseCardResp 517 | /** ! @brief 微信返回第三方请求选择卡券结果 518 | * 519 | */ 520 | 521 | @interface WXChooseCardResp : BaseResp 522 | @property (nonatomic,retain) NSArray* cardAry; 523 | @end 524 | 525 | #pragma mark - WXMediaMessage 526 | 527 | /*! @brief 多媒体消息结构体 528 | * 529 | * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 530 | */ 531 | @interface WXMediaMessage : NSObject 532 | 533 | +(WXMediaMessage *) message; 534 | 535 | /** 标题 536 | * @note 长度不能超过512字节 537 | */ 538 | @property (nonatomic, retain) NSString *title; 539 | /** 描述内容 540 | * @note 长度不能超过1K 541 | */ 542 | @property (nonatomic, retain) NSString *description; 543 | /** 缩略图数据 544 | * @note 大小不能超过32K 545 | */ 546 | @property (nonatomic, retain) NSData *thumbData; 547 | /** 548 | * @note 长度不能超过64字节 549 | */ 550 | @property (nonatomic, retain) NSString *mediaTagName; 551 | /** 552 | * 553 | */ 554 | @property (nonatomic, retain) NSString *messageExt; 555 | @property (nonatomic, retain) NSString *messageAction; 556 | /** 557 | * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 558 | */ 559 | @property (nonatomic, retain) id mediaObject; 560 | 561 | /*! @brief 设置消息缩略图的方法 562 | * 563 | * @param image 缩略图 564 | * @note 大小不能超过32K 565 | */ 566 | - (void) setThumbImage:(UIImage *)image; 567 | 568 | @end 569 | 570 | 571 | 572 | #pragma mark - WXImageObject 573 | /*! @brief 多媒体消息中包含的图片数据对象 574 | * 575 | * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 576 | * @note imageData成员不能为空 577 | * @see WXMediaMessage 578 | */ 579 | @interface WXImageObject : NSObject 580 | /*! @brief 返回一个WXImageObject对象 581 | * 582 | * @note 返回的WXImageObject对象是自动释放的 583 | */ 584 | +(WXImageObject *) object; 585 | 586 | /** 图片真实数据内容 587 | * @note 大小不能超过10M 588 | */ 589 | @property (nonatomic, retain) NSData *imageData; 590 | 591 | @end 592 | 593 | 594 | #pragma mark - WXMusicObject 595 | /*! @brief 多媒体消息中包含的音乐数据对象 596 | * 597 | * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 598 | * @note musicUrl和musicLowBandUrl成员不能同时为空。 599 | * @see WXMediaMessage 600 | */ 601 | @interface WXMusicObject : NSObject 602 | /*! @brief 返回一个WXMusicObject对象 603 | * 604 | * @note 返回的WXMusicObject对象是自动释放的 605 | */ 606 | +(WXMusicObject *) object; 607 | 608 | /** 音乐网页的url地址 609 | * @note 长度不能超过10K 610 | */ 611 | @property (nonatomic, retain) NSString *musicUrl; 612 | /** 音乐lowband网页的url地址 613 | * @note 长度不能超过10K 614 | */ 615 | @property (nonatomic, retain) NSString *musicLowBandUrl; 616 | /** 音乐数据url地址 617 | * @note 长度不能超过10K 618 | */ 619 | @property (nonatomic, retain) NSString *musicDataUrl; 620 | 621 | /**音乐lowband数据url地址 622 | * @note 长度不能超过10K 623 | */ 624 | @property (nonatomic, retain) NSString *musicLowBandDataUrl; 625 | 626 | @end 627 | 628 | 629 | 630 | #pragma mark - WXVideoObject 631 | /*! @brief 多媒体消息中包含的视频数据对象 632 | * 633 | * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 634 | * @note videoUrl和videoLowBandUrl不能同时为空。 635 | * @see WXMediaMessage 636 | */ 637 | @interface WXVideoObject : NSObject 638 | /*! @brief 返回一个WXVideoObject对象 639 | * 640 | * @note 返回的WXVideoObject对象是自动释放的 641 | */ 642 | +(WXVideoObject *) object; 643 | 644 | /** 视频网页的url地址 645 | * @note 长度不能超过10K 646 | */ 647 | @property (nonatomic, retain) NSString *videoUrl; 648 | /** 视频lowband网页的url地址 649 | * @note 长度不能超过10K 650 | */ 651 | @property (nonatomic, retain) NSString *videoLowBandUrl; 652 | 653 | @end 654 | 655 | 656 | 657 | #pragma mark - WXWebpageObject 658 | /*! @brief 多媒体消息中包含的网页数据对象 659 | * 660 | * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 661 | * @see WXMediaMessage 662 | */ 663 | @interface WXWebpageObject : NSObject 664 | /*! @brief 返回一个WXWebpageObject对象 665 | * 666 | * @note 返回的WXWebpageObject对象是自动释放的 667 | */ 668 | +(WXWebpageObject *) object; 669 | 670 | /** 网页的url地址 671 | * @note 不能为空且长度不能超过10K 672 | */ 673 | @property (nonatomic, retain) NSString *webpageUrl; 674 | 675 | @end 676 | 677 | 678 | 679 | #pragma mark - WXAppExtendObject 680 | /*! @brief 多媒体消息中包含的App扩展数据对象 681 | * 682 | * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, 683 | * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 684 | * @note url,extInfo和fileData不能同时为空 685 | * @see WXMediaMessage 686 | */ 687 | @interface WXAppExtendObject : NSObject 688 | /*! @brief 返回一个WXAppExtendObject对象 689 | * 690 | * @note 返回的WXAppExtendObject对象是自动释放的 691 | */ 692 | +(WXAppExtendObject *) object; 693 | 694 | /** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 695 | * @note 长度不能超过10K 696 | */ 697 | @property (nonatomic, retain) NSString *url; 698 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 699 | * @note 长度不能超过2K 700 | */ 701 | @property (nonatomic, retain) NSString *extInfo; 702 | /** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 703 | * @note 大小不能超过10M 704 | */ 705 | @property (nonatomic, retain) NSData *fileData; 706 | 707 | @end 708 | 709 | 710 | 711 | #pragma mark - WXEmoticonObject 712 | /*! @brief 多媒体消息中包含的表情数据对象 713 | * 714 | * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 715 | * @see WXMediaMessage 716 | */ 717 | @interface WXEmoticonObject : NSObject 718 | 719 | /*! @brief 返回一个WXEmoticonObject对象 720 | * 721 | * @note 返回的WXEmoticonObject对象是自动释放的 722 | */ 723 | +(WXEmoticonObject *) object; 724 | 725 | /** 表情真实数据内容 726 | * @note 大小不能超过10M 727 | */ 728 | @property (nonatomic, retain) NSData *emoticonData; 729 | 730 | @end 731 | 732 | 733 | 734 | #pragma mark - WXFileObject 735 | /*! @brief 多媒体消息中包含的文件数据对象 736 | * 737 | * @see WXMediaMessage 738 | */ 739 | @interface WXFileObject : NSObject 740 | 741 | /*! @brief 返回一个WXFileObject对象 742 | * 743 | * @note 返回的WXFileObject对象是自动释放的 744 | */ 745 | +(WXFileObject *) object; 746 | 747 | /** 文件后缀名 748 | * @note 长度不超过64字节 749 | */ 750 | @property (nonatomic, retain) NSString *fileExtension; 751 | 752 | /** 文件真实数据内容 753 | * @note 大小不能超过10M 754 | */ 755 | @property (nonatomic, retain) NSData *fileData; 756 | 757 | @end 758 | 759 | 760 | #pragma mark - WXLocationObject 761 | /*! @brief 多媒体消息中包含的地理位置数据对象 762 | * 763 | * 微信终端和第三方程序之间传递消息中包含的地理位置数据对象。 764 | * @see WXMediaMessage 765 | */ 766 | @interface WXLocationObject : NSObject 767 | 768 | /*! @brief 返回一个WXLocationObject对象 769 | * 770 | * @note 返回的WXLocationObject对象是自动释放的 771 | */ 772 | +(WXLocationObject *) object; 773 | 774 | /** 地理位置信息 775 | * @note 经纬度 776 | */ 777 | @property (nonatomic, assign) double lng; //经度 778 | @property (nonatomic, assign) double lat; //纬度 779 | 780 | @end 781 | 782 | 783 | #pragma mark - WXTextObject 784 | /*! @brief 多媒体消息中包含的文本数据对象 785 | * 786 | * 微信终端和第三方程序之间传递消息中包含的文本数据对象。 787 | * @see WXMediaMessage 788 | */ 789 | @interface WXTextObject : NSObject 790 | 791 | /*! @brief 返回一个WXTextObject对象 792 | * 793 | * @note 返回的WXTextObject对象是自动释放的 794 | */ 795 | +(WXTextObject *) object; 796 | 797 | /** 地理位置信息 798 | * @note 文本内容 799 | */ 800 | @property (nonatomic, retain) NSString *contentText; 801 | 802 | @end 803 | 804 | -------------------------------------------------------------------------------- /WechatAuthSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // WechatAuthSDK.h 3 | // WechatAuthSDK 4 | // 5 | // Created by 李凯 on 13-11-29. 6 | // Copyright (c) 2013年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | enum AuthErrCode { 13 | WechatAuth_Err_Ok = 0, //Auth成功 14 | WechatAuth_Err_NormalErr = -1, //普通错误 15 | WechatAuth_Err_NetworkErr = -2, //网络错误 16 | WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败 17 | WechatAuth_Err_Cancel = -4, //用户取消授权 18 | WechatAuth_Err_Timeout = -5, //超时 19 | }; 20 | 21 | @protocol WechatAuthAPIDelegate 22 | @optional 23 | 24 | - (void)onAuthGotQrcode:(UIImage *)image; //得到二维码 25 | - (void)onQrcodeScanned; //二维码被扫描 26 | - (void)onAuthFinish:(int)errCode AuthCode:(NSString *)authCode; //成功登录 27 | 28 | @end 29 | 30 | @interface WechatAuthSDK : NSObject{ 31 | NSString *_sdkVersion; 32 | __weak id _delegate; 33 | } 34 | 35 | @property(nonatomic, weak) id delegate; 36 | @property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号 37 | 38 | /*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调 39 | * 40 | * @param appId 微信开发者ID 41 | * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同 42 | * @param timeStamp 时间戳 43 | * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔 44 | * @param signature 签名 45 | * @param schemeData 会在扫码后拼在scheme后 46 | * @return 成功返回YES,失败返回NO 47 | 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。 48 | */ 49 | 50 | - (BOOL)Auth:(NSString *)appId 51 | nonceStr:(NSString *)nonceStr 52 | timeStamp:(NSString*)timeStamp 53 | scope:(NSString *)scope 54 | signature:(NSString *)signature 55 | schemeData:(NSString *)schemeData; 56 | 57 | 58 | /*! @brief 暂停登录请求 59 | * 60 | * @return 成功返回YES,失败返回NO。 61 | */ 62 | - (BOOL)StopAuth; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /libWeChatSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickcheng/libWeChatSDK/fceb75b70a1c11ed0bfc47b5f388979adb02eec9/libWeChatSDK.a -------------------------------------------------------------------------------- /libWeChatSDK.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "libWeChatSDK" 4 | s.version = "1.7.5" 5 | s.license = { 6 | :type => "Copyright", 7 | :text => " Copyright (c) 2012 Tencent. All rights reserved.\n" 8 | } 9 | s.summary = "WeChatSDK for Cocoapods convenience." 10 | s.homepage = "https://open.weixin.qq.com/" 11 | s.authors = { 12 | "Tencent" => "weixinapp@qq.com" 13 | } 14 | s.source = { 15 | :git => "https://github.com/nickcheng/libWeChatSDK.git", 16 | :tag => "#{s.version}" 17 | } 18 | s.platform = :ios 19 | s.source_files = "*.h" 20 | s.public_header_files = "*.h" 21 | s.preserve_paths = "libWeChatSDK.a" 22 | s.vendored_libraries = "libWeChatSDK.a" 23 | s.xcconfig = { 24 | 'LIBRARY_SEARCH_PATHS' => '"$(PODS_ROOT)/libWeChatSDK"', 25 | 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/libWeChatSDK"' 26 | } 27 | s.requires_arc = false 28 | s.frameworks = 'SystemConfiguration', 'CoreTelephony', 'CFNetwork' 29 | s.libraries = 'z', 'sqlite3.0', 'c++' 30 | 31 | end 32 | --------------------------------------------------------------------------------