奇门介绍文档
奇门场景接入介绍
奇门白皮书
奇门接口参考文档
API模拟对方发送数据
一、开发阶段,下载SDK;
发送参考,使用sdk无需考虑验签;若无sdk参考开放平台-文档中心:
QimenClient client = new DefaultQimenClient(url, appkey, secret);
OrderCancelRequest req = new OrderCancelRequest();
req.setCustomerId("stub-cust-code");
req.setVersion("2.0");
req.setWarehouseCode("W1234");
req.setOwnerCode("H1234");
req.setOrderCode("O1234");
req.setOrderId("WQ1234");
req.setOrderType("JYCK");
req.setCancelReason("已经退货");
req.setRemark("备注");
OrderCancelResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
接收奇门发送:
import com.alibaba.dubbo.common.utils.IOUtils;
import com.alibaba.fastjson.JSONObject;
import com.qimen.api.QimenRequest;
import com.qimen.api.QimenResponse;
import com.qimen.api.response.SingleitemSynchronizeResponse;
import com.qimen.api.response.SnReportResponse;
import com.taobao.api.internal.parser.xml.ObjectXmlParser;
import com.taobao.api.internal.spi.SpiUtils;
import com.taobao.api.internal.util.XmlWriter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/qimen")
@Slf4j
@ResponseBody
public class QiMenAcceptController extends QiMenAcceptCommon {
@RequestMapping(value = "/accept", method = {RequestMethod. POST , RequestMethod. GET },consumes ={MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE} ,produces ={ MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE})
public String accept(HttpServletRequest request){
QimenResponse qimenResponse=null;
Object form="";
String requestData="";
Map<String, Object> allRequestParam = getAllRequestParam(request);
try {
Map<String, String[]> parameterMap = request.getParameterMap();
log.info("接收奇门回调接,获取query参数为={}",JSONObject.toJSONString(parameterMap));
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
requestData = IOUtils.read(reader);
log.info("接收奇门回调接口,requestData={}", requestData);
//String data =requestData= URLDecoder.decode(data,"UTF-8");
//log.info("接收奇门回调接,解析body为={}",data);
//验证签名
boolean result = SpiUtils.checkSign4TextRequest(request,requestData, qiMenConfig.getSecret());;
log.info("验证签名result={}",result);
form=allRequestParam.getOrDefault(XmlExercise.FROM,XmlExercise.XML_TYPE);
if(!result){
qimenResponse = new SnReportResponse();
qimenResponse.setCode(ApiCodeEnums.SIGN_ERROR.getCode());
qimenResponse.setFlag(ApiCodeEnums.SIGN_ERROR.getName());
qimenResponse.setMessage(ApiCodeEnums.SIGN_ERROR.getMessage());
}else{
qimenResponse = null;//TODO 可以进行根据method方法名进行分发策略.dispatcher(requestData, allRequestParam);
if(!StringUtils.isEmpty(qimenResponse)){
//判断是否返回正确
if(qimenResponse.getCode().equals(ApiCodeEnums.SUCCESS.getCode())){
}
}else{
throw new Exception("返回类型异常!");
}
}
} catch (Exception e) {
e.printStackTrace();
log.info("接收奇门回调接口异常",e);
qimenResponse = new SingleitemSynchronizeResponse();
qimenResponse.setFlag(ApiCodeEnums.ERROR_ACCEPT.getName());
qimenResponse.setCode(ApiCodeEnums.ERROR_ACCEPT.getCode());
qimenResponse.setMessage(String.format(ApiCodeEnums.ERROR_ACCEPT.getMessage(),e.getMessage()));
}finally {
return parseQiMen(qimenResponse);
}
}
/**
* 奇门类转换xml,sdk自带的,也可以自己写
* @param ob
* @return
*/
public String parseQiMen(Object ob){
String write="";
XmlWriter tRsp= new XmlWriter(true, "request", QimenRequest.class);
write = tRsp.write(ob);
return write;
}
/**
* 奇门转换处理,sdk自带的,也可以自己写
* @param body
* @param t 转换类,列如SingleitemSynchronizeRequest 商品同步接口
* @param <T>
* @return
*/
public <T>T convertQiMenClass(String body,Class<T> t) {
try {
ObjectXmlParser xmlParser = new ObjectXmlParser(t);
Object classObject = xmlParser.parse(body, "qimen1");
return (T)classObject;
} catch (Exception e) {
e.printStackTrace();
log.info("转换奇门数据异常",e);
}
return null;
}
/**
* 获取客户端请求参数中所有的信息
* @param request
* @return
*/
private Map<String, Object> getAllRequestParam(HttpServletRequest request) {
Map<String, Object> res = new HashMap<String, Object>();
res.put("paramUrl",request.getRequestURL()+"?"+request.getQueryString());
Enumeration<String> temp = request.getParameterNames();
if (null != temp) {
while (temp.hasMoreElements()) {
String en = (String) temp.nextElement();
String value = request.getParameter(en);
res.put(en, value);
//如果字段的值为空,判断若值为空,则删除这个字段>
if (null == res.get(en) || "".equals(res.get(en))) {
res.remove(en);
}
}
}
return res;
}
二.进入自测阶段,选择对应接口点击接入,自测通过后可以进入联调阶段;联调对方发起后,审核通过后;需要配置CustomerId,以及联调回调url; 联调结束;对方发起上线申请;需要配置线上CustomerId,以及联调回调url;