1. 程式人生 > >Springboot 整合 中國移動MAS HTTP1.0 實現簡訊傳送服務(二)

Springboot 整合 中國移動MAS HTTP1.0 實現簡訊傳送服務(二)

原因:身份驗證傳入的引數包含中文企業名,因為本地編碼格式是支援中文的;而客戶的伺服器中文卻亂碼,導致傳給中國移動MAS伺服器的是亂碼的資訊。

解決:非常簡單,將中文資訊轉為UTF-8。例如(%E5%8D%9A%E5%AE%A2%E5%9B%AD)

    // 身份驗證方法
    public static CheckRes check () throws UnsupportedEncodingException {
     // 轉為 UTF-8格式:案例  String req
= "ec_name="+ URLEncoder.encode(ec_name, "UTF-8") +"&user_name="+user_name+"&user_passwd="+user_passwd ; System.out.println(
"傳入引數:"+req); HttpRequest httpRequest = new HttpRequest() ; String checkStr = httpRequest.sendPost(checkUrl,req) ; //返回驗證資訊的 回參 System.out.println("驗證身份結果:"+checkStr); CheckRes checkRes = JSONUtils.json2pojo(checkStr,CheckRes.class); String mas_user_id = checkRes.getMas_user_id() ; System.out.println(
"mas_user_id:"+mas_user_id); return checkRes ; }

這樣就不會出現授權失敗情況了!