上传宜搭测试代码2
This commit is contained in:
parent
f7521389d1
commit
b43fb164d8
@ -15,6 +15,20 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
//上传宜搭相关包
|
||||
using AlibabaCloud.SDK.Dingtalkcrm_1_0.Models;
|
||||
using AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models;
|
||||
using AlibabaCloud.SDK.Dingtalkyida_1_0.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using Tea;
|
||||
|
||||
|
||||
using AlibabaCloud.SDK.Dingtalkoauth2_1_0;
|
||||
using AlibabaCloud.SDK.Dingtalkyida_1_0;
|
||||
using AlibabaCloud.OpenApiClient.Models;
|
||||
|
||||
|
||||
namespace MqttClient
|
||||
{
|
||||
public class MqttClientService
|
||||
@ -24,6 +38,16 @@ namespace MqttClient
|
||||
private readonly string _connectionString = "server=139.224.232.211;port=3308;database=fgassembly;user=root;password=doantech123;";
|
||||
|
||||
|
||||
//上传宜搭信息
|
||||
static string tokenAppKey = "dingcr4tknewvoasaz2a";
|
||||
static string tokenAppSecret = "EX-7YQjw14pI1bVNA5UyoQT4JcRNfwLFxKQ5n9rt6Kq8GCfsSdaONzYwHYvvIiXF";
|
||||
|
||||
static string appType = "APP_GLOIXDZ2INP8IW70XB8Y";
|
||||
static string systemToken = "R7E66JC1W1QZ2HVOCJUX99KHDNP92XDRRUPGMDI1";
|
||||
static string userId = "011117285547650088";
|
||||
static string formUuid = "FORM-EA85012D92D444BE92BB1017FF4ACAF8ISRW";
|
||||
|
||||
|
||||
public event Action<string> MessageReceived; // 通知UI层
|
||||
|
||||
public MqttClientService()
|
||||
@ -271,7 +295,140 @@ namespace MqttClient
|
||||
|
||||
|
||||
|
||||
//上传宜搭代码
|
||||
//上传宜搭相关代码
|
||||
|
||||
/// <summary>
|
||||
/// 创建 OAuth2 客户端(获取 token 用)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client CreateClient()
|
||||
{
|
||||
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
|
||||
config.Protocol = "https";
|
||||
config.RegionId = "central";
|
||||
return new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取钉钉 AccessToken
|
||||
/// </summary>
|
||||
/// <returns>AccessToken 字符串</returns>
|
||||
public static string GetDingDingToken()
|
||||
{
|
||||
string strToken = string.Empty;
|
||||
GetAccessTokenResponse token = null;
|
||||
|
||||
var client = CreateClient();
|
||||
var getAccessTokenRequest = new GetAccessTokenRequest
|
||||
{
|
||||
AppKey = tokenAppKey,
|
||||
AppSecret = tokenAppSecret,
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
token = client.GetAccessToken(getAccessTokenRequest);
|
||||
}
|
||||
catch (TeaException err)
|
||||
{
|
||||
Console.WriteLine($"获取 token 异常:{err.Code} --- {err.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"获取 token 异常:{ex.Message}");
|
||||
}
|
||||
|
||||
return token != null ? token.Body.AccessToken : string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建宜搭客户端
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AlibabaCloud.SDK.Dingtalkyida_1_0.Client CreateYidaClient()
|
||||
{
|
||||
Config config = new Config();
|
||||
config.Protocol = "https";
|
||||
config.RegionId = "central";
|
||||
return new AlibabaCloud.SDK.Dingtalkyida_1_0.Client(config);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 上传测试数据到宜搭
|
||||
/// </summary>
|
||||
/// <param name="accessToken"></param>
|
||||
/// <returns></returns>
|
||||
public static bool UploadTestDataToYida(string accessToken)
|
||||
{
|
||||
var client = CreateYidaClient();
|
||||
|
||||
// 先写死 24 个字段数据,对应宜搭唯一标识
|
||||
var dataDict = new Dictionary<string, object>
|
||||
{
|
||||
{ "textField_pbadehs", "测试值_supplier_code" },
|
||||
{ "textField_1xi9sfn", "测试值_supplier_name" },
|
||||
{ "textField_59qd85u", "测试值_vehicle_model" },
|
||||
{ "textField_bvm0r0n", "测试值_part_number" },
|
||||
{ "textField_36ov0ev", "测试值_part_name" },
|
||||
{ "textField_2az30vq", "测试值_configuration" },
|
||||
{ "textField_rqco1qe", "测试值_working_station" },
|
||||
{ "textField_u0til0r", "测试值_parameter_name" },
|
||||
{ "textField_grwfv60", "测试值_parameter_value" },
|
||||
{ "textField_8jzbj2n", "测试值_tolerance_lower" },
|
||||
{ "textField_m4zc2at", "测试值_tolerance_upper" },
|
||||
{ "textField_7van6hm", "测试值_is_qualification" },
|
||||
{ "dateField_h0zk520", DateTime.Now.ToString("yyyy-MM-dd") },
|
||||
{ "textField_wyvrvdh", "测试值_leader_part" },
|
||||
{ "textField_7uday88", "测试值_value" },
|
||||
{ "textField_sodkifq", "测试值_lowlimit" },
|
||||
{ "textField_flmgqq8", "测试值_uplimit" },
|
||||
{ "textField_x18839h", "测试值_intime" },
|
||||
{ "textField_nvdzppr", "测试值_out_of_tolerance_cause" },
|
||||
{ "textField_dea190j", "测试值_reproduction_measure" },
|
||||
{ "textField_ftm1wp0", "测试值_reformation_picture" },
|
||||
{ "textField_ukkzy00", "测试值_leader" },
|
||||
{ "textField_w5b9nts", "测试值_abnormality_type" },
|
||||
{ "textField_buwiwu2", "测试值_leader_out_protection" }
|
||||
|
||||
};
|
||||
|
||||
// 转成 JSON
|
||||
string jsonData = JsonConvert.SerializeObject(dataDict);
|
||||
|
||||
// 构建请求
|
||||
var headers = new SaveFormDataHeaders { XAcsDingtalkAccessToken = accessToken };
|
||||
var request = new SaveFormDataRequest
|
||||
{
|
||||
AppType = appType,
|
||||
SystemToken = systemToken,
|
||||
UserId = userId,
|
||||
Language = "zh_CN",
|
||||
FormUuid = formUuid,
|
||||
FormDataJson = jsonData
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var response = client.SaveFormDataWithOptions(request, headers, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
|
||||
if (response != null)
|
||||
{
|
||||
Console.WriteLine("✅ 上传成功,实例ID:" + response.Body.Result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (TeaException err)
|
||||
{
|
||||
Console.WriteLine($"上传异常:{err.Code} --- {err.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"上传异常:{ex.Message}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user