Commit 5adb1afb authored by 黄毅's avatar 黄毅

双语

parent 4de105ca
package com.egolm.payment.config;
import java.util.Locale;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
@Configuration
public class I18Config extends WebMvcConfigurerAdapter {
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
// 默认语言
slr.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
return slr;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
// 参数名
lci.setParamName("langID");
return lci;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
}
...@@ -3,8 +3,6 @@ package com.egolm.payment.controller; ...@@ -3,8 +3,6 @@ package com.egolm.payment.controller;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -16,14 +14,10 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -16,14 +14,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.common.web.ServletUtil;
import com.egolm.payment.pojo.TSystemCtrl;
import com.egolm.payment.service.WxChatService; import com.egolm.payment.service.WxChatService;
import com.egolm.payment.util.PayContstrant; import com.egolm.payment.util.I18NUtils;
import com.egolm.payment.util.WxSignUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -58,7 +52,7 @@ public class WxApiController { ...@@ -58,7 +52,7 @@ public class WxApiController {
String status = request.getParameter("status"); String status = request.getParameter("status");
if(!StringUtil.isNotEmpty(terminal,langID,orderId,status)){ if(!StringUtil.isNotEmpty(terminal,langID,orderId,status)){
return Rjx.jsonErr().setCode(-100).setMessage("参数不能为空").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Param_notEmpty")).toJson();
} }
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("orderId", orderId); params.put("orderId", orderId);
...@@ -82,7 +76,7 @@ public class WxApiController { ...@@ -82,7 +76,7 @@ public class WxApiController {
return Rjx.jsonOk().toJson(); return Rjx.jsonOk().toJson();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return Rjx.jsonErr().setCode(-100).setMessage("查询异常").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Query_error")).toJson();
} }
} }
} }
...@@ -22,6 +22,7 @@ import com.egolm.common.bean.Rjx; ...@@ -22,6 +22,7 @@ import com.egolm.common.bean.Rjx;
import com.egolm.common.web.ServletUtil; import com.egolm.common.web.ServletUtil;
import com.egolm.payment.pojo.TSystemCtrl; import com.egolm.payment.pojo.TSystemCtrl;
import com.egolm.payment.service.WxChatService; import com.egolm.payment.service.WxChatService;
import com.egolm.payment.util.I18NUtils;
import com.egolm.payment.util.PayContstrant; import com.egolm.payment.util.PayContstrant;
import com.egolm.payment.util.WxSignUtil; import com.egolm.payment.util.WxSignUtil;
...@@ -61,7 +62,7 @@ public class WxMiniApiController { ...@@ -61,7 +62,7 @@ public class WxMiniApiController {
logger.info(terminal+" 获取openid时 code 为:"+code); logger.info(terminal+" 获取openid时 code 为:"+code);
if(!StringUtil.isNotEmpty(code,terminal,langID)) { if(!StringUtil.isNotEmpty(code,terminal,langID)) {
return Rjx.jsonErr().setCode(-100).setMessage("参数不能为空").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Param_notEmpty")).toJson();
} }
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
...@@ -72,7 +73,7 @@ public class WxMiniApiController { ...@@ -72,7 +73,7 @@ public class WxMiniApiController {
params.put("appid",tSystemCtrl.getsValue1()); params.put("appid",tSystemCtrl.getsValue1());
params.put("secret",tSystemCtrl.getsValue2()); params.put("secret",tSystemCtrl.getsValue2());
}else { }else {
return Rjx.jsonErr().setCode(-100).setMessage("openId获取失败").set("errorMsg", "数据字典参数未配置").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Openid_failure")).set("errorMsg", I18NUtils.getMessage(langID, "Msg_Datadictionary_notConfig")).toJson();
} }
params.put("js_code", code); params.put("js_code", code);
...@@ -111,10 +112,9 @@ public class WxMiniApiController { ...@@ -111,10 +112,9 @@ public class WxMiniApiController {
}) })
@RequestMapping(value="/unifiedorder",method=RequestMethod.GET) @RequestMapping(value="/unifiedorder",method=RequestMethod.GET)
public String unifiedorder(HttpServletRequest request, HttpServletResponse response){ public String unifiedorder(HttpServletRequest request, HttpServletResponse response){
try {
String terminal = request.getParameter("terminal"); String terminal = request.getParameter("terminal");
String langID = request.getParameter("langID"); String langID = request.getParameter("langID");
try {
SortedMap<Object,Object> params = new TreeMap<Object,Object>(); SortedMap<Object,Object> params = new TreeMap<Object,Object>();
String appid = ""; String appid = "";
...@@ -132,11 +132,11 @@ public class WxMiniApiController { ...@@ -132,11 +132,11 @@ public class WxMiniApiController {
params.put("md5Key", md5Key); params.put("md5Key", md5Key);
if(!StringUtil.isNotEmpty(appid,mch_id,notify_url,md5Key)) { if(!StringUtil.isNotEmpty(appid,mch_id,notify_url,md5Key)) {
return Rjx.jsonErr().setCode(-100).setMessage("支付失败").set("errorMsg", "数据字典参数配置不完整").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Pay_failure")).set("errorMsg", I18NUtils.getMessage(langID, "Msg_Datadictionary_inComplete")).toJson();
} }
}else { }else {
return Rjx.jsonErr().setCode(-100).setMessage("支付失败").set("errorMsg", "数据字典参数未配置").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Pay_failure")).set("errorMsg", I18NUtils.getMessage(langID, "Msg_Datadictionary_notConfig")).toJson();
} }
params.put("nonce_str",StringUtil.getNonceStr()); params.put("nonce_str",StringUtil.getNonceStr());
...@@ -165,7 +165,7 @@ public class WxMiniApiController { ...@@ -165,7 +165,7 @@ public class WxMiniApiController {
resultMap.put("md5Key", md5Key); resultMap.put("md5Key", md5Key);
if(!WxSignUtil.checkSign( resultMap, return_sign)){ if(!WxSignUtil.checkSign( resultMap, return_sign)){
return Rjx.jsonErr().setCode(-100).setMessage("微信下单失败").set("errorMsg", "返回结果签名不一致").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_WXOrder_failure")).set("errorMsg", I18NUtils.getMessage(langID, "Msg_backSign_isconsistent")).toJson();
} }
String prepay_id = resultMap.get("prepay_id"); String prepay_id = resultMap.get("prepay_id");
...@@ -188,20 +188,20 @@ public class WxMiniApiController { ...@@ -188,20 +188,20 @@ public class WxMiniApiController {
if(return_code.equals("FAIL")){ if(return_code.equals("FAIL")){
String return_msg = resultMap.get("return_msg"); String return_msg = resultMap.get("return_msg");
return Rjx.jsonErr().setCode(-100).setMessage("微信下单失败").set("errorMsg", return_msg).toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_WXOrder_failure")).set("errorMsg", return_msg).toJson();
} }
if(return_code.equals("SUCCESS") && result_code.equals("FAIL")){ if(return_code.equals("SUCCESS") && result_code.equals("FAIL")){
String err_code = resultMap.get("err_code"); String err_code = resultMap.get("err_code");
String err_code_des = resultMap.get("err_code_des"); String err_code_des = resultMap.get("err_code_des");
return Rjx.jsonErr().setCode(-100).setMessage("微信下单失败").set("errorMsg", err_code).set("err_code_des", err_code_des).toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_WXOrder_failure")).set("errorMsg", err_code).set("err_code_des", err_code_des).toJson();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return Rjx.jsonErr().setCode(-100).setMessage("微信下单失败").set("errorMsg","生成预支付订单异常").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_WXOrder_failure")).set("errorMsg",I18NUtils.getMessage(langID, "Msg_Prepaid_order_error")).toJson();
} }
return Rjx.jsonErr().setCode(-100).setMessage("微信下单失败").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_WXOrder_failure")).toJson();
} }
...@@ -240,11 +240,11 @@ public class WxMiniApiController { ...@@ -240,11 +240,11 @@ public class WxMiniApiController {
md5Key = tSystemCtrl.getsValue5(); md5Key = tSystemCtrl.getsValue5();
if(!StringUtil.isNotEmpty(appid,mch_id,md5Key)) { if(!StringUtil.isNotEmpty(appid,mch_id,md5Key)) {
return Rjx.jsonErr().setCode(-100).setMessage("支付失败").set("errorMsg", "数据字典参数配置不完整").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Pay_failure")).set("errorMsg", I18NUtils.getMessage(langID, "Msg_Datadictionary_inComplete")).toJson();
} }
}else { }else {
return Rjx.jsonErr().setCode(-100).setMessage("支付失败").set("errorMsg", "数据字典参数未配置").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Pay_failure")).set("errorMsg", I18NUtils.getMessage(langID, "Msg_Datadictionary_notConfig")).toJson();
} }
...@@ -276,20 +276,20 @@ public class WxMiniApiController { ...@@ -276,20 +276,20 @@ public class WxMiniApiController {
resultMap.put("md5Key", md5Key); resultMap.put("md5Key", md5Key);
if(!WxSignUtil.checkSign( resultMap, return_sign)){ if(!WxSignUtil.checkSign( resultMap, return_sign)){
return Rjx.jsonErr().setCode(-100).setMessage("退款失败").set("errorMsg","返回结果签名不一致").toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Refund_failure")).set("errorMsg",I18NUtils.getMessage(langID, "Msg_backSign_isconsistent")).toJson();
} }
return Rjx.jsonOk().setMessage("微信退款成功").toJson(); return Rjx.jsonOk().setMessage(I18NUtils.getMessage(langID, "Msg_Refund_success")).toJson();
} }
if(return_code.equals("FAIL")){ if(return_code.equals("FAIL")){
String return_msg = resultMap.get("return_msg"); String return_msg = resultMap.get("return_msg");
return Rjx.jsonErr().setCode(-100).setMessage("退款失败").set("errorMsg",return_msg).toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Refund_failure")).set("errorMsg",return_msg).toJson();
} }
if(return_code.equals("SUCCESS") && result_code.equals("FAIL")){ if(return_code.equals("SUCCESS") && result_code.equals("FAIL")){
String err_code = resultMap.get("err_code"); String err_code = resultMap.get("err_code");
String err_code_des = resultMap.get("err_code_des"); String err_code_des = resultMap.get("err_code_des");
return Rjx.jsonErr().setCode(-100).setMessage("退款失败").set("err_code", err_code).set("errorMsg", err_code_des).toJson(); return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Refund_failure")).set("err_code", err_code).set("errorMsg", err_code_des).toJson();
} }
......
package com.egolm.payment.util;
import java.text.MessageFormat;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import com.egolm.common.StringUtil;
/**
*
* @ClassName: I18NUtil
* @Description: TODO( 图际化工具类)
* @author 张永
* @date 2018年4月11日 下午5:36:27
*
*/
@Component
public class I18NUtils {
private static MessageSource source;
public static void main(String[] args) {
System.out.println(getMessage("zh", "Msg_check_key_set","AAA"));
}
@Autowired
public void init(MessageSource source) {
I18NUtils.source = source;
}
/**
*
* <p>Title: </p>
* <p>Description: </p>
* @param LangID 语言标识 与IDC中设置 的对应
* @param key 获取的key
* @param values key中对应的值用于替换 里面的 {0} {1}...
* @return
* @author 张永
* @date 2018年4月11日 下午8:35:15
*/
public static String getMessage(String LangID,String key,Object...values){
if(StringUtil.isEmpty(LangID)){ //为空默认为中文
Locale.setDefault(Locale.CHINA);
}else{
if(LangID.equals("900")){ //英文
Locale.setDefault(Locale.ENGLISH);
}else{
Locale.setDefault(Locale.CHINA);
}
}
Locale locale = LocaleContextHolder.getLocale();
System.out.println("locale---------------"+locale);
String msg = source.getMessage(key, null, locale);
return MessageFormat.format(msg, values);
}
}
spring.profiles.active=dev spring.profiles.active=dev
spring.messages.basename=messages
\ No newline at end of file
Msg_Param_notEmpty=参数不能为空
Msg_Query_error=查询异常
Msg_Openid_failure=openId获取失败
Msg_Datadictionary_notConfig=数据字典参数未配置
Msg_Datadictionary_inComplete=数据字典参数配置不完整
Msg_Pay_failure=支付失败
Msg_WXOrder_failure=微信下单失败
Msg_backSign_isconsistent=返回结果签名不一致
Msg_Prepaid_order_error=生成预支付订单异常
Msg_Refund_failure=退款失败
Msg_Refund_success=微信退款成功
\ No newline at end of file
Msg_Param_notEmpty=Parameter can not be empty
Msg_Query_error=Query error
Msg_Openid_failure=Get openId failure
Msg_Datadictionary_notConfig=Data dictionary parameters not configured
Msg_Datadictionary_inComplete=Data dictionary parameter configuration is incomplete
Msg_Pay_failure=Pay failure
Msg_WXOrder_failure=WxChat order failure
Msg_backSign_isconsistent=Return result signature is inconsistent
Msg_Prepaid_order_error=Generate prepaid order exception
Msg_Refund_failure=Refund failure
Msg_Refund_success=WxChat refund success
Msg_Param_notEmpty=\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A
Msg_Query_error=\u67E5\u8BE2\u5F02\u5E38
Msg_Openid_failure=openId\u83B7\u53D6\u5931\u8D25
Msg_Datadictionary_notConfig=\u6570\u636E\u5B57\u5178\u53C2\u6570\u672A\u914D\u7F6E
Msg_Datadictionary_inComplete=\u6570\u636E\u5B57\u5178\u53C2\u6570\u914D\u7F6E\u4E0D\u5B8C\u6574
Msg_Pay_failure=\u652F\u4ED8\u5931\u8D25
Msg_WXOrder_failure=\u5FAE\u4FE1\u4E0B\u5355\u5931\u8D25
Msg_backSign_isconsistent=\u8FD4\u56DE\u7ED3\u679C\u7B7E\u540D\u4E0D\u4E00\u81F4
Msg_Prepaid_order_error=\u751F\u6210\u9884\u652F\u4ED8\u8BA2\u5355\u5F02\u5E38
Msg_Refund_failure=\u9000\u6B3E\u5931\u8D25
Msg_Refund_success=\u5FAE\u4FE1\u9000\u6B3E\u6210\u529F
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment