mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
5.0
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package com.gitee.sop.support.constants;
|
||||
|
||||
/**
|
||||
* RPC附件name
|
||||
*
|
||||
* @author 六如
|
||||
*/
|
||||
public class AttachmentNames {
|
||||
|
||||
/**
|
||||
* 分配给开发者的应用ID
|
||||
*/
|
||||
public static final String APP_ID = "client.app_id";
|
||||
/**
|
||||
* 接口名称
|
||||
*/
|
||||
public static final String API_NAME = "client.method";
|
||||
/**
|
||||
* 调用的接口版本
|
||||
*/
|
||||
public static final String VERSION = "client.version";
|
||||
/**
|
||||
* 开放平台主动通知商户服务器里指定的页面http/https路径
|
||||
*/
|
||||
public static final String NOTIFY_URL = "client.notify_url";
|
||||
/**
|
||||
* OAuth 2.0授权token
|
||||
*/
|
||||
public static final String APP_AUTH_TOKEN = "client.app_auth_token";
|
||||
/**
|
||||
* 请求id
|
||||
*/
|
||||
public static final String CLIENT_IP = "client.ip";
|
||||
/**
|
||||
* 请求traceId
|
||||
*/
|
||||
public static final String TRACE_ID = "client.trace_id";
|
||||
/**
|
||||
* 请求locale
|
||||
*/
|
||||
public static final String LOCALE = "client.locale";
|
||||
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.gitee.sop.support.dto;
|
||||
package com.gitee.sop.support.context;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Locale;
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class DefaultOpenRequest implements OpenRequest, Serializable {
|
||||
public class DefaultOpenContext implements OpenContext, Serializable {
|
||||
private static final long serialVersionUID = -3218354527911979685L;
|
||||
|
||||
/**
|
@@ -1,77 +1,50 @@
|
||||
package com.gitee.sop.support.context;
|
||||
|
||||
import com.gitee.sop.support.constants.AttachmentNames;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public class OpenContext {
|
||||
|
||||
public interface OpenContext {
|
||||
|
||||
/**
|
||||
* 获取appId
|
||||
*/
|
||||
public static String getAppId() {
|
||||
return getAttachment(AttachmentNames.APP_ID);
|
||||
}
|
||||
String getAppId();
|
||||
|
||||
/**
|
||||
* 获取apiName
|
||||
*/
|
||||
public static String getApiName() {
|
||||
return getAttachment(AttachmentNames.API_NAME);
|
||||
}
|
||||
String getApiName();
|
||||
|
||||
/**
|
||||
* 获取version
|
||||
*/
|
||||
public static String getVersion() {
|
||||
return getAttachment(AttachmentNames.VERSION);
|
||||
}
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* 获取token,没有返回null
|
||||
*/
|
||||
public static String getAppAuthToken() {
|
||||
return getAttachment(AttachmentNames.APP_AUTH_TOKEN);
|
||||
}
|
||||
String getAppAuthToken();
|
||||
|
||||
/**
|
||||
* 获取客户端ip
|
||||
*/
|
||||
public static String getClientIp() {
|
||||
return getAttachment(AttachmentNames.CLIENT_IP);
|
||||
}
|
||||
String getClientIp();
|
||||
|
||||
/**
|
||||
* 获取回调地址
|
||||
*/
|
||||
public static String getNotifyUrl() {
|
||||
return getAttachment(AttachmentNames.NOTIFY_URL);
|
||||
}
|
||||
String getNotifyUrl();
|
||||
|
||||
/**
|
||||
* 获取唯一请求id
|
||||
*/
|
||||
public static String getTraceId() {
|
||||
return getAttachment(AttachmentNames.TRACE_ID);
|
||||
}
|
||||
String getTraceId();
|
||||
|
||||
/**
|
||||
* 获取locale
|
||||
*/
|
||||
public static Locale getLocale() {
|
||||
String langTag = getAttachment(AttachmentNames.LOCALE);
|
||||
if (langTag == null) {
|
||||
return Locale.SIMPLIFIED_CHINESE;
|
||||
}
|
||||
return Locale.forLanguageTag(langTag);
|
||||
}
|
||||
Locale getLocale();
|
||||
|
||||
private static String getAttachment(String key) {
|
||||
return RpcContext.getServerAttachment().getAttachment(key);
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +0,0 @@
|
||||
package com.gitee.sop.support.dto;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public interface OpenRequest {
|
||||
|
||||
/**
|
||||
* 获取appId
|
||||
*/
|
||||
String getAppId();
|
||||
|
||||
/**
|
||||
* 获取apiName
|
||||
*/
|
||||
String getApiName();
|
||||
|
||||
/**
|
||||
* 获取version
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* 获取token,没有返回null
|
||||
*/
|
||||
String getAppAuthToken();
|
||||
|
||||
/**
|
||||
* 获取客户端ip
|
||||
*/
|
||||
String getClientIp();
|
||||
|
||||
/**
|
||||
* 获取回调地址
|
||||
*/
|
||||
String getNotifyUrl();
|
||||
|
||||
/**
|
||||
* 获取唯一请求id
|
||||
*/
|
||||
String getTraceId();
|
||||
|
||||
/**
|
||||
* 获取locale
|
||||
*/
|
||||
Locale getLocale();
|
||||
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package com.gitee.sop.support.exception;
|
||||
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import com.gitee.sop.support.message.I18nMessage;
|
||||
import com.gitee.sop.support.message.OpenMessage;
|
||||
import com.gitee.sop.support.message.OpenMessageFactory;
|
||||
@@ -29,7 +28,7 @@ public class OpenException extends RuntimeException {
|
||||
}
|
||||
|
||||
public OpenException(I18nMessage openError, Object... params) {
|
||||
this(openError, OpenContext.getLocale(), params);
|
||||
this(openError, Locale.SIMPLIFIED_CHINESE, params);
|
||||
}
|
||||
|
||||
public OpenException(String subCode, String subMsg, String solution) {
|
||||
|
@@ -1,2 +1,2 @@
|
||||
com.gitee.sop.support.dto.CommonFileData
|
||||
com.gitee.sop.support.dto.DefaultOpenRequest
|
||||
com.gitee.sop.support.context.DefaultOpenContext
|
||||
|
Reference in New Issue
Block a user