创建用户动态信息

更新时间:2025.06.22

通过此接口同步非微信支付渠道的会员动态信息到微信支付商家名片会员

接口限频:按服务商商户号维度 5次/秒

接口说明

支持商户:【普通服务商】

请求方式:【POST】/v3/brand/partner/card-member/user-feeds

请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点

     【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看

请求参数

Header  HTTP头参数

 Authorization  必填 string

请参考签名认证生成认证信息


 Accept  必填 string

请设置为application/json


 Content-Type  必填 string

请设置为application/json


body  包体参数

 brand_id  必填   string(32)

【品牌ID】 商家进驻微信支付品牌商家后获得的品牌ID(灰度期间联系微信支付运营获取),用于标记该会员卡的归属方


 card_id  必填   string(32)

【会员卡模板ID】 商家创建会员卡模板成功后系统返回的会员卡模板ID


 user_card_code  必填   string(32)

【会员卡code】 会员在一个会员卡模板下的唯一标识,用户领取会员卡后获得的code。只能填写数字/英文/半角标点。平台支持2种会员卡code分配类型:(1)SYSTEM_ALLOCATE 微信支付系统分配,用户领取会员卡时从微信系统分配24位数字作为会员code;(2)MERCHANT_ALLOCATE 商家分配,商家同步会员开通结果时传入,用户开卡成功或失败都以商家传入的code作为会员卡code。


 openid  必填   string(128)

【用户标识】 用户在品牌商家会员卡模板AppID下的唯一标识,获取方式详见参数说明


 out_request_no  必填   string(64)

【商家请求单号】 商家创建用户动态信息凭据号。商家自定义,注意保持唯一性,仅供参考的格式:品牌ID+时间戳+流水号。字符仅允许包含英文半角的数字、字母、连接线-和下划线_。


 cell  必填   string(128)

【会员动态内容】 与下单同步用户实时动态文档中的cell参数保持一致。

请求示例

Java
Go
curl

需配合微信支付工具库 WXPayUtility 使用,请参考 Java 

1package com.java.demo;
2
3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777
4
5import com.google.gson.annotations.SerializedName;
6import com.google.gson.annotations.Expose;
7import okhttp3.MediaType;
8import okhttp3.OkHttpClient;
9import okhttp3.Request;
10import okhttp3.RequestBody;
11import okhttp3.Response;
12
13import java.io.IOException;
14import java.io.UncheckedIOException;
15import java.security.PrivateKey;
16import java.security.PublicKey;
17import java.util.ArrayList;
18import java.util.HashMap;
19import java.util.List;
20import java.util.Map;
21
22/**
23 * 创建用户动态信息
24 */
25public class CreateUserFeeds {
26  private static String HOST = "https://api.mch.weixin.qq.com";
27  private static String METHOD = "POST";
28  private static String PATH = "/v3/brand/partner/card-member/user-feeds";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    CreateUserFeeds client = new CreateUserFeeds(
33      "19xxxxxxxx",                    // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340
34      "1DDE55AD98Exxxxxxxxxx",         // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924
35      "/path/to/apiclient_key.pem",    // 商户API证书私钥文件路径,本地文件路径
36      "PUB_KEY_ID_xxxxxxxxxxxxx",      // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589
37      "/path/to/wxp_pub.pem"           // 微信支付公钥文件路径,本地文件路径
38    );
39
40    CreateUserFeedsRequest request = new CreateUserFeedsRequest();
41    request.brandId = "1004";
42    request.cardId = "pbLatjvWOibDc5-TBnbUk1pD12o0";
43    request.userCardCode = "478515832665";
44    request.openid = "obLatjnx9gnqzS4myYGmLZ7LgLBA";
45    request.outRequestNo = "100002322019090134234sfdf";
46    request.cell = "15_1200_1";
47    try {
48      UserFeeds response = client.run(request);
49
50      // TODO: 请求成功,继续业务逻辑
51      System.out.println(response);
52    } catch (WXPayUtility.ApiException e) {
53      // TODO: 请求失败,根据状态码执行不同的逻辑
54      e.printStackTrace();
55    }
56  }
57
58  public UserFeeds run(CreateUserFeedsRequest request) {
59    String uri = PATH;
60    String reqBody = WXPayUtility.toJson(request);
61
62    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
63    reqBuilder.addHeader("Accept", "application/json");
64    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
65    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody));
66    reqBuilder.addHeader("Content-Type", "application/json");
67    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody);
68    reqBuilder.method(METHOD, requestBody);
69    Request httpRequest = reqBuilder.build();
70
71    // 发送HTTP请求
72    OkHttpClient client = new OkHttpClient.Builder().build();
73    try (Response httpResponse = client.newCall(httpRequest).execute()) {
74      String respBody = WXPayUtility.extractBody(httpResponse);
75      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
76        // 2XX 成功,验证应答签名
77        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
78            httpResponse.headers(), respBody);
79
80        // 从HTTP应答报文构建返回数据
81        return WXPayUtility.fromJson(respBody, UserFeeds.class);
82      } else {
83        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
84      }
85    } catch (IOException e) {
86      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
87    }
88  }
89
90  private final String mchid;
91  private final String certificateSerialNo;
92  private final PrivateKey privateKey;
93  private final String wechatPayPublicKeyId;
94  private final PublicKey wechatPayPublicKey;
95
96  public CreateUserFeeds(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
97    this.mchid = mchid;
98    this.certificateSerialNo = certificateSerialNo;
99    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
100    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
101    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
102  }
103
104  public static class CreateUserFeedsRequest {
105    @SerializedName("brand_id")
106    public String brandId;
107  
108    @SerializedName("card_id")
109    public String cardId;
110  
111    @SerializedName("user_card_code")
112    public String userCardCode;
113  
114    @SerializedName("openid")
115    public String openid;
116  
117    @SerializedName("out_request_no")
118    public String outRequestNo;
119  
120    @SerializedName("cell")
121    public String cell;
122  }
123  
124  public static class UserFeeds {
125    @SerializedName("brand_id")
126    public String brandId;
127  
128    @SerializedName("card_id")
129    public String cardId;
130  
131    @SerializedName("user_card_code")
132    public String userCardCode;
133  
134    @SerializedName("out_request_no")
135    public String outRequestNo;
136  
137    @SerializedName("cell")
138    public String cell;
139  }
140  
141}
142

应答参数

200 OK

 brand_id  必填   string(16)

【品牌ID】 商家进驻微信支付品牌商家后获得的品牌ID(灰度期间联系微信支付运营获取),用于标记该会员卡的归属方


 card_id  必填   string

【会员卡模板ID】 商家创建会员卡模板成功后系统返回的会员卡模板ID


 user_card_code  必填   string(32)

【会员卡code】 会员在一个会员卡模板下的唯一标识,用户领取会员卡后获得的code。只能填写数字/英文/半角标点。平台支持2种会员卡code分配类型:(1)SYSTEM_ALLOCATE 微信支付系统分配,用户领取会员卡时从微信系统分配24位数字作为会员code;(2)MERCHANT_ALLOCATE 商家分配,商家同步会员开通结果时传入,用户开卡成功或失败都以商家传入的code作为会员卡code。


 out_request_no  必填   string

【商家请求单号】 商家创建用户动态信息凭据号。商家自定义,注意保持唯一性,仅供参考的格式:品牌ID+时间戳+流水号。字符仅允许包含英文半角的数字、字母、连接线-和下划线_。


 cell  必填   string(128)

【会员动态内容】 与下单同步用户实时动态文档中的cell参数保持一致。

应答示例

200 OK

1{
2  "brand_id" : "1004",
3  "card_id" : "pbLatjvWOibDc5-TBnbUk1pD12o0",
4  "user_card_code" : "478515832665",
5  "out_request_no" : "100002322019090134234sfdf",
6  "cell" : "15_1200_1"
7}
8

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

请根据错误提示正确传入参数

400

INVALID_REQUEST

HTTP 请求不符合微信支付 APIv3 接口规则

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

业务错误码

状态码

错误码

描述

解决方案

403

NO_AUTH

商家没有权限使用该动态信息模板

请跟对应运营申请该模板权限

 

反馈
咨询
目录
置顶