Java支付宝小程序发送模板消息

本文主要是实现Java支付宝小程序发送模板消息:

       /**
 * 支付宝 模板通知
 * @author Mark
 * @param userid
 * @param fromId
 * @param price
 * @param amount
 * @param remake
 * @return
 */
public static String Alipaysuccessmessage(String userid, String fromId, double price, double amount,
        String remake) {
    AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
            "你的支付宝APPID", "你的支付宝私钥", "json",
            "GBK", "支付宝公钥", "RSA2");
    AlipayOpenAppMiniTemplatemessageSendRequest request = new AlipayOpenAppMiniTemplatemessageSendRequest();
    request.setBizContent("{" + "\"to_user_id\":\"" + userid + "\"," + "\"form_id\":\"" + fromId + "\","
            + "\"user_template_id\":\"你的模板ID\","
            + "\"page\":\"模板消息需要跳转的页面\"," + "\"data\":\"{\\\"keyword1\\\":{\\\"value\\\":\\\"" + price
            + "\\\"},\\\"keyword2\\\":{\\\"value\\\":\\\"" + amount + "\\\"},\\\"keyword3\\\":{\\\"value\\\":\\\""
            + remake + "\\\"},\\\"keyword4\\\":{\\\"value\\\":\\\"钱包余额可以随时退还\\\"}}\"" + "}");
    AlipayOpenAppMiniTemplatemessageSendResponse response = null;
    try {
        response = alipayClient.execute(request);
    } catch (AlipayApiException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (response.isSuccess()) {
        return "Success";
    } else {
        return "Fail";
    }
}

你可能感兴趣的:(java,支付宝,小程序,支付宝小程序模板消息)