com.alipay.api.response.AlipayOpenPublicMessageSingleSendResponse Java Examples

The following examples show how to use com.alipay.api.response.AlipayOpenPublicMessageSingleSendResponse. 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: AliPayApi.java    From AlipayWechatPlatform with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 发送支付宝模板消息API;
 *
 * @param tplMsg 模板消息对象
 * @return 是否调用成功
 * @author Leibniz
 */
public static JsonObject sendTemplateMessage(TemplateMessage tplMsg, Account wxAccount) {
    AliAccountInfo aliAccountInfo = new AliAccountInfo(wxAccount.getZfbappid(), wxAccount.getZfbprivkey(), wxAccount.getZfbpubkey(), null, null, null);
    AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 获取支付宝连接
    AlipayOpenPublicMessageSingleSendRequest request = new AlipayOpenPublicMessageSingleSendRequest(); // 创建发送模版消息请求
    request.setBizContent(tplMsg.toString()); // 设置请求的业务内容
    AlipayOpenPublicMessageSingleSendResponse response = null;

    try {
        response = alipayClient.execute(request); // 发送请求,并获得响应
    } catch (AlipayApiException e) { // 捕获异常
        LOG.error("调用支付宝模板消息接口时抛出AlipayApiException异常", e); // 打异常日志
    }

    // 判断响应是否为空
    String errmsg = null;
    if (response != null) { // 响应为空
        // 判断响应是否成功
        if(response.isSuccess()) { // 响应成功,即发送模版消息成功
            LOG.debug("调用成功code={},msg={}", new Object[]{response.getCode(), response.getMsg()}); // 打成功日志
            return new JsonObject().put("status", "success").put("sucmsg", response.getMsg()); // 返回发送成功标识
        } else { // 响应失败,即发送模版消息失败
            LOG.error("调用失败code={},subCode={},subMsg={}", new Object[]{response.getCode(), response.getSubCode(), response.getSubMsg()}); // 打失败日志
            errmsg = response.getSubCode() + ":" + response.getSubMsg();
        }
    } else { // 响应为空
        LOG.error("调用支付宝模板消息接口时发生异常,返回响应对象为null!"); // 打异常日志
        errmsg = "response is null";
    }
    return new JsonObject().put("status", "fail").put("errmsg", errmsg); // 返回发送失败标识
}
 
Example #2
Source File: AlipayOpenPublicMessageSingleSendRequest.java    From alipay-sdk-java-all with Apache License 2.0 4 votes vote down vote up
public Class<AlipayOpenPublicMessageSingleSendResponse> getResponseClass() {
	return AlipayOpenPublicMessageSingleSendResponse.class;
}
 
Example #3
Source File: AlipayOpenPublicMessageSingleSendRequest.java    From alipay-sdk with Apache License 2.0 4 votes vote down vote up
public Class<AlipayOpenPublicMessageSingleSendResponse> getResponseClass() {
	return AlipayOpenPublicMessageSingleSendResponse.class;
}
 
Example #4
Source File: AlipayOpenPublicMessageSingleSendRequest.java    From pay with Apache License 2.0 4 votes vote down vote up
public Class<AlipayOpenPublicMessageSingleSendResponse> getResponseClass() {
	return AlipayOpenPublicMessageSingleSendResponse.class;
}
 
Example #5
Source File: JwSendMessageAPI.java    From jeewx-api with Apache License 2.0 3 votes vote down vote up
/**
 * 单发模板消息(新版API)
 * @param model
 * @param config
 * @return
 * @throws AlipayApiException
 */
public static AlipayOpenPublicMessageSingleSendResponse messageSingleSendNew(AlipayOpenPublicMessageSingleSendModel model,AlipayConfig config) throws AlipayApiException{
	AlipayOpenPublicMessageSingleSendRequest request = new AlipayOpenPublicMessageSingleSendRequest();
	String json = JSONObject.toJSONString(model);
	request.setBizContent(json);
	return AlipayClientFactory.getAlipayClientInstance(config).execute(request);
}