Beispiel #1
0
        /// <summary>
        /// 获取AccessToken
        /// </summary>
        /// <returns></returns>
        public IActionResult OnPostHistoryAccessToken()
        {
            var result = _yilianyunSdkHook.GetAccessToken(MachineCode);

            if (string.IsNullOrEmpty(result?.Access_Token))
            {
                Message = "未存储AccessToken";
            }
            else
            {
                Message = "获取AccessToken成功,到期时间:" + result.ExpiressEndTime;
            }
            AccessToken  = result?.Access_Token;
            RefreshToken = result?.Refresh_Token;
            return(Page());
        }
        /// <summary>
        /// 终端授权 (永久授权) 仅支持自有应用,将自动调用 GetAccessToken 授权
        /// </summary>
        /// <param name="machine_code">易联云打印机终端号</param>
        /// <param name="msign">易联云终端密钥</param>
        /// <param name="phone">手机卡号码(可填)</param>
        /// <param name="print_name">自定义打印机名称(可填)</param>
        /// <param name="skipSave">跳过保存(可填)</param>
        /// <returns></returns>
        public YilianyunBaseOutputModel <AccessTokenOutputModel> AuthTerminal(string machine_code, string msign, string phone = null, string print_name = null, bool skipSave = true)
        {
            var accessModel = _yilianyunSdkHook.GetAccessToken(machine_code);

            if (accessModel == null || string.IsNullOrEmpty(accessModel.Access_Token))
            {
                var accessTokenResult = GetAccessToken(null, true);
                if (accessTokenResult.IsError())
                {
                    return(accessTokenResult);
                }
                accessTokenResult.Body.PrinterName  = print_name;
                accessTokenResult.Body.Phone        = phone;
                accessTokenResult.Body.Machine_Code = machine_code;
                if (!skipSave)
                {
                    var saveTokenResult = _yilianyunSdkHook.SaveToken(accessTokenResult.Body);
                    if (saveTokenResult.IsError())
                    {
                        return(saveTokenResult);
                    }
                }
                accessModel = accessTokenResult.Body;
            }
            Dictionary <string, object> dicData = GetInitPostData();

            //终端号
            dicData.Add("machine_code", machine_code);
            //终端密钥
            dicData.Add("msign", msign);
            //授权token
            dicData.Add("access_token", accessModel.Access_Token);
            //手机卡号
            if (!string.IsNullOrEmpty(phone))
            {
                dicData.Add("phone", phone);
            }
            //打印机名称
            if (!string.IsNullOrEmpty(print_name))
            {
                dicData.Add("print_name", print_name);
            }

            var responseResult = _httpClient.HttpPost <YilianyunBaseOutputModel <AccessTokenOutputModel> >("/printer/addprinter", dicData);

            if (responseResult.IsSuccess())
            {
                responseResult.Body = accessModel;
            }
            return(responseResult);
        }