zoukankan      html  css  js  c++  java
  • ios 微信登录相关

    引入项目的文件

    info.plist 添加内容

    WXApi.registerApp(Config.wx.APP_ID,enableMTA: true)//注册微信api(在AppDelegate里面注册,AppDelegate 需要实现WxApiDelegate)

    WXApi.isWXAppInstalled()     //检测微信是否安装

    WXApi.isWXAppSupport()      //检测当前安装微信app,是否支持当前api

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
            WXApi.handleOpen(url, delegate: self)
            return true
        }
        
        func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
            WXApi.handleOpen(url, delegate: self)
            return true
        }
        
        func onReq(_ req: BaseReq!) {
            print("======onReq=(req.type)");
        }
        
        func onResp(_ resp: BaseResp!) {
            print("======onResp:type=(resp.type);errCode=(resp.errCode)")
            if(resp.isKind(of: SendAuthResp.self)){
    //微信登录回调
    if(resp.errCode == 0 && resp.type == 0){ let response:SendAuthResp = resp as! SendAuthResp print("code=(response.code)") print("state=(response.state)") //这里获取到code可以进行获取用户信息处理了 }else{ toastShow(title: "授权失败") } } if(resp.isKind(of: SendMessageToWXResp.self)){ if(resp.errCode == 0 && resp.type == 0){ toastShow(title: "分享成功") }else{ toastShow(title: "分享失败") } } }

    微信登录

    let req = SendAuthReq.init();
    req.scope = "snsapi_userinfo"
    req.state = "(arc4random()%100)"
    WXApi.send(req)
  • 相关阅读:
    每日日报2020.9.30 1905
    每日日报2020.10.7 1905
    每日日报2020.10.2 1905
    每日日报2020.9.28 1905
    程序员修炼之道:从小工到专家 九月读书心得 1905
    每日日报2020.9.27 1905
    每日日报2020.9.29 1905
    每日日报2020.10.6 1905
    每日日报2020.10.5 1905
    每日总结2
  • 原文地址:https://www.cnblogs.com/rchao/p/9237719.html
Copyright © 2011-2022 走看看