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

发送POST请求 中文乱码 #4

Closed
chenjunjie45 opened this issue Sep 9, 2022 · 9 comments
Closed

发送POST请求 中文乱码 #4

chenjunjie45 opened this issue Sep 9, 2022 · 9 comments
Labels
question Further information is requested

Comments

@chenjunjie45
Copy link

发送POST请求 中文乱码,已经设置了lang("zh_CN"),有解决方法吗

@hb0730
Copy link
Collaborator

hb0730 commented Sep 14, 2022

@chenjunjie45 不好意思现在才看到,请问是那种模式,能否发出json格式的内容

@hb0730
Copy link
Collaborator

hb0730 commented Oct 24, 2022

开发者长时间未反馈

@hb0730 hb0730 closed this as completed Oct 24, 2022
@felix9ia
Copy link

felix9ia commented Jul 23, 2024

现在这个问题依然存在...
image

  PostMessage message = PostMessage.build().lang(
                PostLang.builder()
                        .lang("zh_cn")
                        .unit(
                                PostUnit.build()
                                        .title(orderDO.getShopName() + " 订单支付成功:" + orderNo)
                                        .addTags(
                                                PostTags.build().addTags(
                                                        TextTag.builder().text("商品为: " + goodsNames).build(),
                                                        TextTag.builder().text("支付金额为: " + orderDO.getTotalFee()).build(),
                                                        TextTag.builder().text("取餐码为: " + orderDO.getVerificationCode()).build(),
                                                        ATag.builder().text("请查看").href("http://www.example.com/").build(),
                                                        AtTag.builder().atAll(true).build()
                                                )
                                        )
                        )
                        .build()
        );
        FeishuRobotClient send = new FeishuRobotClient();
        send.setSecret(feishuRobotToken);
        send.setWebhook(feishuRobotWebhookUrl);
        FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message);
        log.info("发送飞书通知成功:" + feiShuRobotResponse.getMsg());

@hb0730 hb0730 reopened this Jul 23, 2024
@hb0730
Copy link
Collaborator

hb0730 commented Jul 24, 2024

现在这个问题依然存在... image

  PostMessage message = PostMessage.build().lang(
                PostLang.builder()
                        .lang("zh_cn")
                        .unit(
                                PostUnit.build()
                                        .title(orderDO.getShopName() + " 订单支付成功:" + orderNo)
                                        .addTags(
                                                PostTags.build().addTags(
                                                        TextTag.builder().text("商品为: " + goodsNames).build(),
                                                        TextTag.builder().text("支付金额为: " + orderDO.getTotalFee()).build(),
                                                        TextTag.builder().text("取餐码为: " + orderDO.getVerificationCode()).build(),
                                                        ATag.builder().text("请查看").href("http://www.example.com/").build(),
                                                        AtTag.builder().atAll(true).build()
                                                )
                                        )
                        )
                        .build()
        );
        FeishuRobotClient send = new FeishuRobotClient();
        send.setSecret(feishuRobotToken);
        send.setWebhook(feishuRobotWebhookUrl);
        FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message);
        log.info("发送飞书通知成功:" + feiShuRobotResponse.getMsg());

并未复现

 PostMessage message = PostMessage.build().lang(
                PostLang.builder()
                        .lang("zh_cn")
                        .unit(
                                PostUnit.build()
                                        .title("订单支付成功")
                                        .addTags(
                                                PostTags.build().addTags(
                                                        TextTag.builder().text("商品为: ").build(),
                                                        TextTag.builder().text("支付金额为: ").build(),
                                                        TextTag.builder().text("取餐码为: ").build(),
                                                        ATag.builder().text("请查看").href("http://www.example.com/").build(),
                                                        AtTag.builder().atAll(true).build()
                                                )
                                        )
                        )
                        .build()
        );
        String webhok = System.getenv("webhook");
        String secret = System.getenv("secret");
        FeishuRobotClient send = new FeishuRobotClient();
        send.setSecret(secret);
        send.setWebhook(webhok);
        FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message);
        System.out.println(feiShuRobotResponse.getMsg());

结果:
image

建议追踪调查发送请求头信息以及请求体信息是否有误

@hb0730 hb0730 added the question Further information is requested label Jul 24, 2024
@felix9ia
Copy link

felix9ia commented Jul 24, 2024

image

build()之后 message 为 null 正常吗 @hb0730

@hb0730
Copy link
Collaborator

hb0730 commented Jul 24, 2024

contentJsonStr只是PostMessage中的属性

    /**
     * 富文本json字符串,优先级高于lang,格式:
     * <PRE>
     * "post": {
     * "zh_cn": {}
     * }
     * <PRE>
     */
    private String contentJsonStr;

核心在于 #toMessage

@felix9ia
Copy link

felix9ia commented Jul 24, 2024

image

image

@hb0730 看着也没问题,咱还需要我手动依赖 hutool-core,告知一下

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-core</artifactId>
            <version>5.8.29</version>
        </dependency>

@hb0730
Copy link
Collaborator

hb0730 commented Jul 24, 2024

json序列化支持gson,jackson,jsonbhb0730/jsons 提供整合支持
http请求支持: httpclient,hutool,okhttp3hb0730/jhttps 提供整合支持

我测试环境为

 <dependency>
            <groupId>io.github.group-robot</groupId>
            <artifactId>feishu-robot-core</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-core</artifactId>
            <version>5.8.28</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-http</artifactId>
            <version>5.8.28</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.17.0</version>
        </dependency>

@felix9ia
Copy link

felix9ia commented Jul 24, 2024

image

通过手动多引入 hutool-http 解决了

   <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-core</artifactId>
            <version>5.8.29</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-http</artifactId>
            <version>5.8.28</version>
        </dependency>

我项目用的是 fastjson2,但是这个问题和 json 工具无关,主要和 hutool-http 有关。

        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.49</version>
        </dependency>

@hb0730 这个依赖导致的问题太隐性了,感觉还有优化的空间,希望大佬抽空优化!感谢!

@hb0730 hb0730 closed this as completed Jul 24, 2024
@hb0730 hb0730 pinned this issue Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants