解决发送短信内容乱码

本文介绍了在发送短信时遇到的字符编码问题及其解决方案,详细解析了短信编码格式和如何确保内容正确显示,帮助读者理解并解决相关问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.jeeplus.common.utils;

import java.io.UnsupportedEncodingException;

import net.sf.json.JSONObject;

@SuppressWarnings("unused")
public class CallPublicServiceUtils {

    private final static String PublicSendShortMessage = "publicService/publicSendShortMessage.htm";

    private static PropertiesLoader loader = new PropertiesLoader("jeeplus.properties");

    public static String pUrl() {
        return loader.getProperty("publicServiceUrl");
    }

    /**
     * 给用户发短信接口
     * @param content       短信内容
     * @param calledTel     手机号
     * @param code          模板编号
     * @return
     * @throws UnsupportedEncodingException
     */
    public static JSONObject publicSendShortMessage(String content, String calledTel, String code) throws UnsupportedEncodingException {
        content = new String(content.getBytes("utf-8"), "gbk");//因为用户收到的短信可能含有乱码,所以需要将此处文本的字符串编码改变到与发送短信的服务器的编码一致

        String result = CallUrlUtil.sendPost(pUrl() + PublicSendShortMessage, "content=" + content + "&calledTel=" + calledTel + "&code=" + code);

        JSONObject json = new JSONObject();
        json = JSONObject.fromObject(result);

        return json;
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值