com.alipay.api.AlipayRequest Java Examples

The following examples show how to use com.alipay.api.AlipayRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlConverter.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param body
 * @return
 */
private ResponseParseItem getXMLSignSourceData(AlipayRequest<?> request, String body) {

    // XML涓�������������
    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    if (indexOfRootNode > 0) {

        return parseXMLSignSourceData(body, rootNode, indexOfRootNode);

    } else if (indexOfErrorRoot > 0) {

        return parseXMLSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #2
Source File: JsonConverter.java    From pay with Apache License 2.0 6 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    // 响应为空则直接返回
    if (StringUtils.isEmpty(responseBody)) {

        return null;
    }

    SignItem signItem = new SignItem();

    // 获取签名
    String sign = getSign(responseBody);
    signItem.setSign(sign);

    // 签名源串
    String signSourceData = getSignSourceData(request, responseBody);
    signItem.setSignSourceDate(signSourceData);

    return signItem;
}
 
Example #3
Source File: XmlConverter.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param body
 * @return
 */
private String getSignSourceData(AlipayRequest<?> request, String body) {

    // XML不同的节点
    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    // 成功或者新版接口
    if (indexOfRootNode > 0) {

        return parseSignSourceData(body, rootNode, indexOfRootNode);
        // 老版本接口
    } else if (indexOfErrorRoot > 0) {

        return parseSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #4
Source File: JsonConverter.java    From alipay-sdk with Apache License 2.0 6 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    // 响应为空则直接返回
    if (StringUtils.isEmpty(responseBody)) {

        return null;
    }

    SignItem signItem = new SignItem();

    // 获取签名
    String sign = getSign(responseBody);
    signItem.setSign(sign);

    // 签名源串
    String signSourceData = getSignSourceData(request, responseBody);
    signItem.setSignSourceDate(signSourceData);

    return signItem;
}
 
Example #5
Source File: JsonConverter.java    From alipay-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param body
 * @return
 */
private String getSignSourceData(AlipayRequest<?> request, String body) {

    // 加签源串起点
    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    // 成功或者新版接口
    if (indexOfRootNode > 0) {

        return parseSignSourceData(body, rootNode, indexOfRootNode);

        // 老版本失败接口
    } else if (indexOfErrorRoot > 0) {

        return parseSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #6
Source File: XmlConverter.java    From pay with Apache License 2.0 6 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    // 响应为空则直接返回
    if (StringUtils.isEmpty(responseBody)) {

        return null;
    }

    SignItem signItem = new SignItem();

    // 获取签名
    String sign = getSign(responseBody);
    signItem.setSign(sign);

    // 签名源串
    String signSourceData = getSignSourceData(request, responseBody);
    signItem.setSignSourceDate(signSourceData);

    return signItem;
}
 
Example #7
Source File: JsonConverter.java    From alipay-sdk with Apache License 2.0 6 votes vote down vote up
/**
 *  获取JSON响应加签内容串
 * 
 * @param request
 * @param body
 * @return
 */
private ResponseParseItem getJSONSignSourceData(AlipayRequest<?> request, String body) {

    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    if (indexOfRootNode > 0) {

        return parseJSONSignSourceData(body, rootNode, indexOfRootNode);

    } else if (indexOfErrorRoot > 0) {

        return parseJSONSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #8
Source File: XmlConverter.java    From alipay-sdk with Apache License 2.0 6 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    // 响应为空则直接返回
    if (StringUtils.isEmpty(responseBody)) {

        return null;
    }

    SignItem signItem = new SignItem();

    // 获取签名
    String sign = getSign(responseBody);
    signItem.setSign(sign);

    // 签名源串
    String signSourceData = getSignSourceData(request, responseBody);
    signItem.setSignSourceDate(signSourceData);

    return signItem;
}
 
Example #9
Source File: XmlConverter.java    From alipay-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param body
 * @return
 */
private String getSignSourceData(AlipayRequest<?> request, String body) {

    // XML不同的节点
    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    // 成功或者新版接口
    if (indexOfRootNode > 0) {

        return parseSignSourceData(body, rootNode, indexOfRootNode);
        // 老版本接口
    } else if (indexOfErrorRoot > 0) {

        return parseSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #10
Source File: JsonConverter.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 *  获取JSON响应加签内容串
 * 
 * @param request
 * @param body
 * @return
 */
private ResponseParseItem getJSONSignSourceData(AlipayRequest<?> request, String body) {

    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    if (indexOfRootNode > 0) {

        return parseJSONSignSourceData(body, rootNode, indexOfRootNode);

    } else if (indexOfErrorRoot > 0) {

        return parseJSONSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #11
Source File: XmlConverter.java    From alipay-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param body
 * @return
 */
private ResponseParseItem getXMLSignSourceData(AlipayRequest<?> request, String body) {

    // XML涓�������������
    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    if (indexOfRootNode > 0) {

        return parseXMLSignSourceData(body, rootNode, indexOfRootNode);

    } else if (indexOfErrorRoot > 0) {

        return parseXMLSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #12
Source File: JsonConverter.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param body
 * @return
 */
private String getSignSourceData(AlipayRequest<?> request, String body) {

    // 加签源串起点
    String rootNode = request.getApiMethodName().replace('.', '_')
                      + AlipayConstants.RESPONSE_SUFFIX;
    String errorRootNode = AlipayConstants.ERROR_RESPONSE;

    int indexOfRootNode = body.indexOf(rootNode);
    int indexOfErrorRoot = body.indexOf(errorRootNode);

    // 成功或者新版接口
    if (indexOfRootNode > 0) {

        return parseSignSourceData(body, rootNode, indexOfRootNode);

        // 老版本失败接口
    } else if (indexOfErrorRoot > 0) {

        return parseSignSourceData(body, errorRootNode, indexOfErrorRoot);
    } else {
        return null;
    }
}
 
Example #13
Source File: ObjectJsonParser.java    From pay with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    Converter converter = new JsonConverter();

    return converter.getSignItem(request, responseBody);
}
 
Example #14
Source File: ObjectXmlParser.java    From alipay-sdk with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                   String encryptType, String encryptKey, String charset)
                                                                                         throws AlipayApiException {

    Converter converter = new XmlConverter();

    return converter.encryptSourceData(request, body, format, encryptType, encryptKey,
        charset);
}
 
Example #15
Source File: ObjectJsonParser.java    From pay with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                   String encryptType, String encryptKey, String charset)
                                                                                         throws AlipayApiException {

    Converter converter = new JsonConverter();

    return converter.encryptSourceData(request, body, format, encryptType, encryptKey,
        charset);
}
 
Example #16
Source File: JsonConverter.java    From pay with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                String encryptType, String encryptKey, String charset)
                                                                                      throws AlipayApiException {

    ResponseParseItem respSignSourceData = getJSONSignSourceData(request, body);

    String bodyIndexContent = body.substring(0, respSignSourceData.getStartIndex());
    String bodyEndContent = body.substring(respSignSourceData.getEndIndex());

    return bodyIndexContent
           + AlipayEncrypt.decryptContent(respSignSourceData.getEncryptContent(), encryptType,
               encryptKey, charset) + bodyEndContent;

}
 
Example #17
Source File: XmlConverter.java    From pay with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                String encryptType, String encryptKey, String charset)
                                                                                      throws AlipayApiException {

    ResponseParseItem respSignSourceData = getXMLSignSourceData(request, body);

    String bodyIndexContent = body.substring(0, respSignSourceData.getStartIndex());
    String bodyEndContent = body.substring(respSignSourceData.getEndIndex());

    return bodyIndexContent
           + AlipayEncrypt.decryptContent(respSignSourceData.getEncryptContent(), encryptType,
               encryptKey, charset) + bodyEndContent;
}
 
Example #18
Source File: ObjectXmlParser.java    From pay with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    Converter converter = new XmlConverter();

    return converter.getSignItem(request, responseBody);
}
 
Example #19
Source File: ObjectXmlParser.java    From pay with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                   String encryptType, String encryptKey, String charset)
                                                                                         throws AlipayApiException {

    Converter converter = new XmlConverter();

    return converter.encryptSourceData(request, body, format, encryptType, encryptKey,
        charset);
}
 
Example #20
Source File: AliPayUtil.java    From wish-pay with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
protected static AlipayResponse getResponse(AlipayClient client, AlipayRequest request) {
    try {
        AlipayResponse response = client.execute(request);
        if (response != null) {
            log.info(response.getBody());
        }
        return response;

    } catch (AlipayApiException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #21
Source File: AbsAlipayService.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
protected AlipayResponse getResponse(AlipayClient client, AlipayRequest request) {
    try {
        AlipayResponse response = client.execute(request);
        if (response != null) {
            log.info(response.getBody());
        }
        return response;

    } catch (AlipayApiException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #22
Source File: ObjectXmlParser.java    From alipay-sdk with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    Converter converter = new XmlConverter();

    return converter.getSignItem(request, responseBody);
}
 
Example #23
Source File: XmlConverter.java    From alipay-sdk with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                String encryptType, String encryptKey, String charset)
                                                                                      throws AlipayApiException {

    ResponseParseItem respSignSourceData = getXMLSignSourceData(request, body);

    String bodyIndexContent = body.substring(0, respSignSourceData.getStartIndex());
    String bodyEndContent = body.substring(respSignSourceData.getEndIndex());

    return bodyIndexContent
           + AlipayEncrypt.decryptContent(respSignSourceData.getEncryptContent(), encryptType,
               encryptKey, charset) + bodyEndContent;
}
 
Example #24
Source File: JsonConverter.java    From alipay-sdk with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.internal.mapping.Converter#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                String encryptType, String encryptKey, String charset)
                                                                                      throws AlipayApiException {

    ResponseParseItem respSignSourceData = getJSONSignSourceData(request, body);

    String bodyIndexContent = body.substring(0, respSignSourceData.getStartIndex());
    String bodyEndContent = body.substring(respSignSourceData.getEndIndex());

    return bodyIndexContent
           + AlipayEncrypt.decryptContent(respSignSourceData.getEncryptContent(), encryptType,
               encryptKey, charset) + bodyEndContent;

}
 
Example #25
Source File: ObjectJsonParser.java    From alipay-sdk with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#encryptSourceData(com.alipay.api.AlipayRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                   String encryptType, String encryptKey, String charset)
                                                                                         throws AlipayApiException {

    Converter converter = new JsonConverter();

    return converter.encryptSourceData(request, body, format, encryptType, encryptKey,
        charset);
}
 
Example #26
Source File: ObjectJsonParser.java    From alipay-sdk with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.api.AlipayParser#getSignItem(com.alipay.api.AlipayRequest, String)
 */
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
                                                                          throws AlipayApiException {

    Converter converter = new JsonConverter();

    return converter.getSignItem(request, responseBody);
}
 
Example #27
Source File: Converter.java    From pay with Apache License 2.0 4 votes vote down vote up
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
String encryptType, String encryptKey, String charset)
                                                      throws AlipayApiException;
 
Example #28
Source File: Converter.java    From pay with Apache License 2.0 4 votes vote down vote up
public SignItem getSignItem(AlipayRequest<?> request, String responseBody)
throws AlipayApiException;
 
Example #29
Source File: AlipayMsgClient.java    From alipay-sdk-java-all with Apache License 2.0 4 votes vote down vote up
public ProduceMsgAck sendMessage(AlipayRequest msgReq) throws InterruptedException {
    if (!isConnected()) {
        throw new NotYetConnectedException();
    }
    Message message = new Message();
    message.setxCmd(MsgConstants.MSG_CMD_PRODUCE);
    message.setxSignType(signType);
    message.setxCharset(charset);
    message.setAppId(appId);
    message.setMsgApi(msgReq.getApiMethodName());
    message.setxTimestamp(System.currentTimeMillis());
    message.setBizContent(new JSONWriter().write(msgReq.getBizModel(), true));
    Message.addSign(message, appPrivateKey);
    ProtocolData protocolData = new ProtocolData();
    protocolData.setMessage(message);
    CountDownLatch signal = new CountDownLatch(1);
    ProtocolDataContext protocolDataContext = new ProtocolDataContext();
    protocolDataContext.setSendData(protocolData);
    protocolDataContext.setSendSignal(signal);
    if (!sendingQueue.offer(protocolData.getStreamId(), 200, TimeUnit.MILLISECONDS)) {
        throw new RuntimeException("too many message not receive ack, refuse new send. streamId:"
                + protocolData.getStreamId());
    }
    sendingContexts.put(protocolData.getStreamId(), protocolDataContext);

    String protocolDataStr = ProtocolData.toStr(protocolData);
    if (AlipayLogger.isBizDebugEnabled()) {
        AlipayLogger.logBizDebug("send msg:" + protocolDataStr.replaceAll("[\r\n]", " "));
    }
    webSocketConnector.send(ProtocolData.toStr(protocolData));
    boolean signalNotify = signal.await(10000, TimeUnit.MILLISECONDS);

    sendingQueue.remove(protocolData.getStreamId());
    sendingContexts.remove(protocolData.getStreamId());
    if (!signalNotify) {
        AlipayLogger.logBizError("wait ack timeout(10s). streamId:" + protocolData.getStreamId());
        throw new RuntimeException("wait ack timeout(10s). streamId:" + protocolData.getStreamId());
    }

    ProtocolData ackData = protocolDataContext.getAckData();
    if (ackData == null) {
        throw new RuntimeException("ack protocol data null. streamId:" + protocolData.getStreamId());
    }
    Message ackMsg = ackData.getMessage();
    if (ackMsg == null) {
        throw new RuntimeException("ack msg null. streamId:" + protocolData.getStreamId());
    }
    ProduceMsgAck produceMsgAck = new ProduceMsgAck();
    produceMsgAck.setxStatus(MsgStatusEnum.fromStr(ackMsg.getxStatus()));
    produceMsgAck.setxCode(ackMsg.getxCode());
    produceMsgAck.setxError(ackMsg.getxError());
    produceMsgAck.setxMessageId(ackMsg.getxMessageId());
    return produceMsgAck;
}
 
Example #30
Source File: Converter.java    From alipay-sdk with Apache License 2.0 2 votes vote down vote up
/**
 *  获取解密后的响应内的真实内容
 * 
 * @param request
 * @param body
 * @param format
 * @param encryptType
 * @param encryptKey
 * @param charset
 * @return
 * @throws AlipayApiException
 */
public String encryptSourceData(AlipayRequest<?> request, String body, String format,
                                   String encryptType, String encryptKey, String charset)
                                                                                         throws AlipayApiException;