WechatAuthSDK.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // WechatAuthSDK.h
  3. // WechatAuthSDK
  4. //
  5. // Created by 李凯 on 13-11-29.
  6. // Copyright (c) 2013年 Tencent. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. NS_ASSUME_NONNULL_BEGIN
  11. enum AuthErrCode {
  12. WechatAuth_Err_Ok = 0, //Auth成功
  13. WechatAuth_Err_NormalErr = -1, //普通错误
  14. WechatAuth_Err_NetworkErr = -2, //网络错误
  15. WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败
  16. WechatAuth_Err_Cancel = -4, //用户取消授权
  17. WechatAuth_Err_Timeout = -5, //超时
  18. };
  19. @protocol WechatAuthAPIDelegate<NSObject>
  20. @optional
  21. - (void)onAuthGotQrcode:(UIImage *)image; //得到二维码
  22. - (void)onQrcodeScanned; //二维码被扫描
  23. - (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录
  24. @end
  25. @interface WechatAuthSDK : NSObject{
  26. NSString *_sdkVersion;
  27. __weak id<WechatAuthAPIDelegate> _delegate;
  28. }
  29. @property(nonatomic, weak, nullable) id<WechatAuthAPIDelegate> delegate;
  30. @property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号
  31. /*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调
  32. *
  33. * @param appId 微信开发者ID
  34. * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同
  35. * @param timeStamp 时间戳
  36. * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔
  37. * @param signature 签名
  38. * @param schemeData 会在扫码后拼在scheme后
  39. * @return 成功返回YES,失败返回NO
  40. 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。
  41. */
  42. - (BOOL)Auth:(NSString *)appId
  43. nonceStr:(NSString *)nonceStr
  44. timeStamp:(NSString *)timeStamp
  45. scope:(NSString *)scope
  46. signature:(NSString *)signature
  47. schemeData:(nullable NSString *)schemeData;
  48. /*! @brief 暂停登录请求
  49. *
  50. * @return 成功返回YES,失败返回NO。
  51. */
  52. - (BOOL)StopAuth;
  53. @end
  54. NS_ASSUME_NONNULL_END