8000 【企业微信】增加家校应用-班级收款接口支持 by 0katekate0 · Pull Request #2692 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

【企业微信】增加家校应用-班级收款接口支持 #2692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.http.up.ByteArrayUploadable;
import jodd.http.upload.ByteArrayUploadable;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
import me.chanjar.weixin.cp.bean.school.WxCpTrade;

import javax.validation.constraints.NotNull;
import java.util.List;
Expand Down Expand Up @@ -57,4 +59,27 @@ public interface WxCpSchoolService {
*/
WxCpResultList getHealthQrCode(@NotNull List<String> userIds, @NotNull Integer type) throws WxErrorException;

/**
* 获取学生付款结果
* 请求方式: POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/school/get_payment_result?access_token=ACCESS_TOKEN
*
* @param paymentId
* @return
* @throws WxErrorException
*/
WxCpPaymentResult getPaymentResult(@NotNull String paymentId) throws WxErrorException;

/**
* 获取订单详情
* 请求方式: POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/school/get_trade?access_token=ACCESS_TOKEN
*
* @param paymentId
* @param tradeNo
* @return
* @throws WxErrorException
*/
WxCpTrade getTrade(@NotNull String paymentId, @NotNull String tradeNo) throws WxErrorException;

}
Original file line number Diff line number Diff line change
10000 Expand Up @@ -7,7 +7,9 @@
import me.chanjar.weixin.cp.api.WxCpSchoolService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
import me.chanjar.weixin.cp.bean.school.WxCpTrade;

import javax.validation.constraints.NotNull;
import java.util.List;
Expand Down Expand Up @@ -64,4 +66,23 @@ public WxCpResultList getHealthQrCode(@NotNull List<String> userIds, @NotNull In
return WxCpResultList.fromJson(responseContent);
}

@Override
public WxCpPaymentResult getPaymentResult(@NotNull String paymentId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_PAYMENT_RESULT);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("payment_id", paymentId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpPaymentResult.fromJson(responseContent);
}

@Override
public WxCpTrade getTrade(@NotNull String paymentId, @NotNull String tradeNo) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_TRADE);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("payment_id", paymentId);
jsonObject.addProperty("trade_no", tradeNo);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpTrade.fromJson(responseContent);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package me.chanjar.weixin.cp.bean.school;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 获取学生付款结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpPaymentResult extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;

@SerializedName("project_name")
private String projectName;

@SerializedName("amount")
private Integer amount;

@SerializedName("payment_result")
private List<PaymentResult> paymentResult;

@Setter
@Getter
public static class PaymentResult{

@SerializedName("student_userid")
private String studentUserId;

@SerializedName("trade_no")
private String tradeNo;

@SerializedName("payer_parent_userid")
private String payerParentUserId;

@SerializedName("trade_state")
private Integer tradeState;

public static PaymentResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, PaymentResult.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

public static WxCpPaymentResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpPaymentResult.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.chanjar.weixin.cp.bean.school;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;

/**
* 获取订单详情.
*
* @author Wang_Wong
*/
@Data
public class WxCpTrade extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;

/**
* 微信交易单号
*/
@SerializedName("transaction_id")
private String transactionId;

/**
* 交易时间
*/
@SerializedName("pay_time")
private Long payTime;

public static WxCpTrade fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpTrade.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ interface School {
String GET_TEACHER_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_teacher_customize_health_info";
String GET_STUDENT_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_student_customize_health_info";
String GET_HEALTH_QRCODE = "/cgi-bin/school/user/get_health_qrcode";

String GET_PAYMENT_RESULT = "/cgi-bin/school/get_payment_result";
String GET_TRADE = "/cgi-bin/school/get_trade";
}

interface Living {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
import me.chanjar.weixin.cp.bean.school.WxCpTrade;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -44,6 +46,34 @@ public void test() throws WxErrorException {
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());


/**
* 获取学生付款结果
* https://developer.work.weixin.qq.com/document/path/94553
*/
String paymentResultStr = "{\"errcode\":0,\"errmsg\":\"ok\",\"project_name\":\"学费\",\"amount\":998,\"payment_result\":[{\"student_userid\":\"xxxx\",\"trade_state\":1,\"trade_no\":\"xxxxx\",\"payer_parent_userid\":\"zhangshan\"}]}";
WxCpPaymentResult cpPaymentResult = WxCpPaymentResult.fromJson(paymentResultStr);
log.info("cpPaymentResult:{}", cpPaymentResult.toJson());

WxCpPaymentResult paymentResult = cpService.getSchoolService().getPaymentResult("");
log.info("paymentResult:{}", paymentResult.toJson());

/**
* 获取订单详情
* https://developer.work.weixin.qq.com/document/path/94554
*/
String tradeStr = "{\n" +
"\t\"errcode\":0,\n" +
"\t\"errmsg\":\"ok\",\n" +
"\t\"transaction_id\":\"xxxxx\", \t \n" +
"\t\"pay_time\":12345\n" +
"}";
WxCpTrade wxCpTrade = WxCpTrade.fromJson(tradeStr);
log.info("wxCpTrade:{}", wxCpTrade.toJson());

WxCpTrade trade = cpService.getSchoolService().getTrade("", "");
log.info("trade:{}", trade.toJson());


/**
* 获取老师健康信息
* https://developer.work.weixin.qq.com/document/path/93744
Expand Down
0