Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

人脸识别SDK,中文乱码 #65

Closed
jinqiangshou opened this issue Dec 5, 2019 · 1 comment
Closed

人脸识别SDK,中文乱码 #65

jinqiangshou opened this issue Dec 5, 2019 · 1 comment

Comments

@jinqiangshou
Copy link

使用人脸识别SDK时发现创建人员库接口中文乱码,出现问题的版本为

<dependency>
    <groupId>com.tencentcloudapi</groupId>
    <artifactId>tencentcloud-sdk-java</artifactId>
    <version>3.0.111</version>
</dependency>

出现问题的示例代码如下:

Credential cred = new Credential("secretId", "secretKey"); // 执行时替换为真实的秘钥
IaiClient iaiClient = new IaiClient(cred, "ap-shanghai");

String str = "China中国";
byte[] b = str.getBytes(StandardCharsets.UTF_8);

// 这里打印出[67, 104, 105, 110, 97, -28, -72, -83, -27, -101, -67],确实是“China中国”的UTF-8编码
System.out.println(Arrays.toString(b));

String[] desc = new String[]{"test"};
CreateGroupRequest createGroupRequest = new CreateGroupRequest();
createGroupRequest.setFaceModelVersion("3.0");
createGroupRequest.setGroupExDescriptions(desc);
createGroupRequest.setGroupId("test_test-test");
createGroupRequest.setGroupName(new String(b, StandardCharsets.UTF_8)); // 将GroupName赋为中文字符串
createGroupRequest.setTag("ThisIsATag");
CreateGroupResponse createGroupResponse = iaiClient.CreateGroup(createGroupRequest);

代码执行后,成功返回,但是去控制台上一看,人员库的名字是乱码,如下图:
企业微信截图_15755267406162

@zqfan
Copy link
Member

zqfan commented Dec 21, 2019

可能你的java环境默认的字符集不是utf8
image
image
今天刚提交了一个变更(将会包含在下个版本中),在发送请求时总是使用utf8,应该可以解决你这个问题

@zqfan zqfan closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants