647556386
3 天以前 bfa52edd6a430978873367426da7b379730da411
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_DTO.MLS;
using WIDESEA_External.IMLSService;
using WIDESEA_IBasicRepository;
using WIDESEA_Common.APIEnum;
using WIDESEA_Core.Helper;
using WIDESEA_Model.Models;
 
namespace WIDESEA_External.PLSService
{
    public class InvokeMLSService : IInvokeMLSService
    {
        private readonly IApiInfoRepository _apiInfoRepository;
 
        public InvokeMLSService(IApiInfoRepository apiInfoRepository)
        {
            _apiInfoRepository = apiInfoRepository;
        }
        JsonSerializerSettings settings = new JsonSerializerSettings
        {
            ContractResolver = new CamelCasePropertyNamesContractResolver()
        };
 
        /// <summary>
        /// 获取token
        /// </summary>
        /// <param name="receiveMLSToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public string ReceiveTokenVoid()
        {
            try
            {
                Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.InvokeMLSTokenApi.ToString());
 
                string MlsPwd = AppSettings.Get("MlsPwd");
                string MlsUser = AppSettings.Get("MlsUser");
                var finalRequest = new
                {
                    mlsUser = MlsUser,
                    mlsPwd = MlsPwd
                };
 
                string requestJson = JsonConvert.SerializeObject(finalRequest, settings);
 
                string response = HttpHelper.Post(apiInfo.ApiAddress, requestJson);
 
                MLSRequestContent mLSRequestContent = response.DeserializeObject<MLSRequestContent>();
 
                if (mLSRequestContent.Code == "0" && mLSRequestContent.Data!= null)
                {
                    apiInfo.Remark = (string)mLSRequestContent.Data;
                    _apiInfoRepository.UpdateData(apiInfo);
                }
                else
                {
                    return "获取token失败,或返回token值为空";
                }
                return response;
            }
            catch(Exception ex)
            {
                return ex.Message;
            }
        }
    }
}