//
//  MineInfoViewController+weChat.swift
//  MobilePortal
//
//  Created by caiyang on 2020/7/28.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension MineInfoViewController {
    /// 是否开启微信
    @objc func getWeChatHttp(){
        SinglePointWeChatHttp.sharedInstance().getWechatScopeListHttpCmd(resultBlock: { [weak self] (value:Any) in
            self?.weChatIDMType(array: value as! NSMutableArray)
        }) {(value:Any) in
            
        }
    }
    func weChatIDMType(array:NSMutableArray){
        for index in 0..<array.count {
            let item:ScopeListHttpModel = array[index] as! ScopeListHttpModel
            /// 1.开启；2.禁用；
            if (index == 0) {
                if (item.state == "1") {
                    sendAuthRequest()
                } else {
                    SMToastView.showMessage("当前IDM不支持微信登录！")
                }
            }
        }
    }
    /// 微信
    @objc func sendAuthRequest(){
        WXApiManager.shared()?.delegate = self
        WXApiManager.shared()?.sendAuthRequest(with: self, delegate: self)
        httpViewModel.access_tokenModel = GetAccessTokenModel()
        httpViewModel.userinfoModel = UserinfoModel()
        httpViewModel.access_tokenModel?.successBlock = {[weak self] (value:Any) in
            self?.httpViewModel.userinfoHttpAction()
        }
        httpViewModel.userinfoModel?.successBlock = {[weak self] (value:Any) in
            self?.getWeChatBindingHttpPostCmd()
        }
        self.httpViewModel.userinfoHttpAction()
    }
    /// WXAuthDelegate
    func wxAuthSucceed(_ code: String!) {
        AccountInfo.sharedInstance().weChat_code = code
        httpViewModel.getCodeWeChatAccess_token()
    }
    func wxAuthDenied() {
        
    }
}
