---
url: "https://pay.weixin.qq.com/doc/v3/merchant/4012487971-java.md"
title: "获取活动详情接口-请求示例-java"
doc_id: 4012487971
example_lang: "java"
---

## Java


需配合微信支付工具库 WXPayUtility 使用，请参考 [Java](https://pay.weixin.qq.com/doc/v3/merchant/4014931831.md)

```
package com.java.demo;

import com.java.utils.WXPayUtility; // 引用微信支付工具库，参考：https://pay.weixin.qq.com/doc/v3/merchant/4014931831

import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.Expose;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获取活动详情接口
 */
public class GetActDetail {
  private static String HOST = "https://api.mch.weixin.qq.com";
  private static String METHOD = "GET";
  private static String PATH = "/v3/marketing/paygiftactivity/activities/{activity_id}";

  public static void main(String[] args) {
    // TODO: 请准备商户开发必要参数，参考：https://pay.weixin.qq.com/doc/v3/merchant/4013070756
    GetActDetail client = new GetActDetail(
      "19xxxxxxxx",                    // 商户号，是由微信支付系统生成并分配给每个商户的唯一标识符，商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756
      "1DDE55AD98Exxxxxxxxxx",         // 商户API证书序列号，如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053
      "/path/to/apiclient_key.pem",     // 商户API证书私钥文件路径，本地文件路径
      "PUB_KEY_ID_xxxxxxxxxxxxx",      // 微信支付公钥ID，如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816
      "/path/to/wxp_pub.pem"           // 微信支付公钥文件路径，本地文件路径
    );

    GetActDetailRequest request = new GetActDetailRequest();
    request.activityId = "10028001";
    try {
      GetActDetailResponse response = client.run(request);
        // TODO: 请求成功，继续业务逻辑
        System.out.println(response);
    } catch (WXPayUtility.ApiException e) {
        // TODO: 请求失败，根据状态码执行不同的逻辑
        e.printStackTrace();
    }
  }

  public GetActDetailResponse run(GetActDetailRequest request) {
    String uri = PATH;
    uri = uri.replace("{activity_id}", WXPayUtility.urlEncode(request.activityId));

    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
    reqBuilder.addHeader("Accept", "application/json");
    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null));
    reqBuilder.method(METHOD, null);
    Request httpRequest = reqBuilder.build();

    // 发送HTTP请求
    OkHttpClient client = new OkHttpClient.Builder().build();
    try (Response httpResponse = client.newCall(httpRequest).execute()) {
      String respBody = WXPayUtility.extractBody(httpResponse);
      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
        // 2XX 成功，验证应答签名
        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
            httpResponse.headers(), respBody);

        // 从HTTP应答报文构建返回数据
        return WXPayUtility.fromJson(respBody, GetActDetailResponse.class);
      } else {
        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
      }
    } catch (IOException e) {
      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
    }
  }

  private final String mchid;
  private final String certificateSerialNo;
  private final PrivateKey privateKey;
  private final String wechatPayPublicKeyId;
  private final PublicKey wechatPayPublicKey;

  public GetActDetail(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
    this.mchid = mchid;
    this.certificateSerialNo = certificateSerialNo;
    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
  }

  public static class GetActDetailRequest {
    @SerializedName("activity_id")
    @Expose(serialize = false)
    public String activityId;
  }

  public static class GetActDetailResponse {
    @SerializedName("activity_id")
    public String activityId;

    @SerializedName("activity_type")
    public ActType activityType;

    @SerializedName("activity_base_info")
    public ActBaseInfo activityBaseInfo;

    @SerializedName("award_send_rule")
    public AwardSendRule awardSendRule;

    @SerializedName("advanced_setting")
    public ActAdvancedSetting advancedSetting;

    @SerializedName("activity_status")
    public ActStatus activityStatus;

    @SerializedName("creator_merchant_id")
    public String creatorMerchantId;

    @SerializedName("belong_merchant_id")
    public String belongMerchantId;

    @SerializedName("pause_time")
    public String pauseTime;

    @SerializedName("recovery_time")
    public String recoveryTime;

    @SerializedName("create_time")
    public String createTime;

    @SerializedName("update_time")
    public String updateTime;
  }

  public enum ActType {
    @SerializedName("FULL_SEND_ACT_TYPE")
    FULL_SEND_ACT_TYPE,
    @SerializedName("STEP_SEND_ACT_TYPE")
    STEP_SEND_ACT_TYPE,
    @SerializedName("SPECIFIC_SEND_ACT_TYPE")
    SPECIFIC_SEND_ACT_TYPE
  }

  public static class ActBaseInfo {
    @SerializedName("activity_name")
    public String activityName;

    @SerializedName("activity_second_title")
    public String activitySecondTitle;

    @SerializedName("merchant_logo_url")
    public String merchantLogoUrl;

    @SerializedName("background_color")
    public String backgroundColor;

    @SerializedName("begin_time")
    public String beginTime;

    @SerializedName("end_time")
    public String endTime;

    @SerializedName("available_periods")
    public AvailablePeriod availablePeriods;

    @SerializedName("out_request_no")
    public String outRequestNo;

    @SerializedName("delivery_purpose")
    public DeliveryPurposeCategory deliveryPurpose;

    @SerializedName("mini_programs_appid")
    public String miniProgramsAppid;

    @SerializedName("mini_programs_path")
    public String miniProgramsPath;
  }

  public static class AwardSendRule {
    @SerializedName("full_send_rule")
    public FullSendRule fullSendRule;
  }

  public static class ActAdvancedSetting {
    @SerializedName("delivery_user_category")
    public DeliveryUserCategory deliveryUserCategory;

    @SerializedName("merchant_member_appid")
    public String merchantMemberAppid;

    @SerializedName("payment_mode")
    public PaymentMode paymentMode;

    @SerializedName("payment_method_information")
    public PaymentMethodInfo paymentMethodInformation;

    @SerializedName("goods_tags")
    public List<String> goodsTags;
  }

  public enum ActStatus {
    @SerializedName("ACT_STATUS_UNKNOWN")
    ACT_STATUS_UNKNOWN,
    @SerializedName("CREATE_ACT_STATUS")
    CREATE_ACT_STATUS,
    @SerializedName("ONGOING_ACT_STATUS")
    ONGOING_ACT_STATUS,
    @SerializedName("TERMINATE_ACT_STATUS")
    TERMINATE_ACT_STATUS,
    @SerializedName("STOP_ACT_STATUS")
    STOP_ACT_STATUS,
    @SerializedName("OVER_TIME_ACT_STATUS")
    OVER_TIME_ACT_STATUS,
    @SerializedName("CREATE_ACT_FAILED")
    CREATE_ACT_FAILED
  }

  public static class AvailablePeriod {
    @SerializedName("available_time")
    public List<AvailableTime> availableTime;

    @SerializedName("available_day_time")
    public List<AvailableDayTime> availableDayTime;
  }

  public enum DeliveryPurposeCategory {
    @SerializedName("OFF_LINE_PAY")
    OFF_LINE_PAY,
    @SerializedName("JUMP_MINI_APP")
    JUMP_MINI_APP
  }

  public static class FullSendRule {
    @SerializedName("transaction_amount_minimum")
    public Long transactionAmountMinimum;

    @SerializedName("send_content")
    public SendContentCategory sendContent;

    @SerializedName("award_type")
    public AwardType awardType;

    @SerializedName("award_list")
    public List<AwardBaseInfo> awardList = new ArrayList<AwardBaseInfo>();

    @SerializedName("merchant_option")
    public SendMerchantOption merchantOption;

    @SerializedName("merchant_id_list")
    public List<String> merchantIdList;
  }

  public enum DeliveryUserCategory {
    @SerializedName("DELIVERY_ALL_PERSON")
    DELIVERY_ALL_PERSON,
    @SerializedName("DELIVERY_MEMBER_PERSON")
    DELIVERY_MEMBER_PERSON
  }

  public static class PaymentMode {
    @SerializedName("payment_scene_list")
    public List<PaymentScene> paymentSceneList;
  }

  public static class PaymentMethodInfo {
    @SerializedName("payment_method")
    public PaymentMethodCategory paymentMethod;

    @SerializedName("bank_abbreviation")
    public String bankAbbreviation;
  }

  public static class AvailableTime {
    @SerializedName("begin_time")
    public String beginTime;

    @SerializedName("end_time")
    public String endTime;
  }

  public static class AvailableDayTime {
    @SerializedName("begin_day_time")
    public String beginDayTime;

    @SerializedName("end_day_time")
    public String endDayTime;
  }

  public enum SendContentCategory {
    @SerializedName("SINGLE_COUPON")
    SINGLE_COUPON,
    @SerializedName("GIFT_PACKAGE")
    GIFT_PACKAGE
  }

  public enum AwardType {
    @SerializedName("BUSIFAVOR")
    BUSIFAVOR
  }

  public static class AwardBaseInfo {
    @SerializedName("stock_id")
    public String stockId;

    @SerializedName("original_image_url")
    public String originalImageUrl;

    @SerializedName("thumbnail_url")
    public String thumbnailUrl;
  }

  public enum SendMerchantOption {
    @SerializedName("IN_SEVICE_COUPON_MERCHANT")
    IN_SEVICE_COUPON_MERCHANT,
    @SerializedName("MANUAL_INPUT_MERCHANT")
    MANUAL_INPUT_MERCHANT
  }

  public enum PaymentScene {
    @SerializedName("APP_SCENE")
    APP_SCENE,
    @SerializedName("SWING_CARD_SCENE")
    SWING_CARD_SCENE,
    @SerializedName("NO_SECRET_SCENE")
    NO_SECRET_SCENE,
    @SerializedName("MINIAPP_SCENE")
    MINIAPP_SCENE,
    @SerializedName("FACE_PAY_SCENE")
    FACE_PAY_SCENE,
    @SerializedName("OTHER_SCENE")
    OTHER_SCENE
  }

  public enum PaymentMethodCategory {
    @SerializedName("CFT")
    CFT,
    @SerializedName("SPECIFIC_BANK_CARD")
    SPECIFIC_BANK_CARD
  }

}

```
