微信官方接口文档:根据卡号查银行信息
access_token获取方式:微信官方接口文档
需要引入lombok依赖
否则手写getter ,setter 方法
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class BankInfoResVo {private String bank_code;private Long bank_id;private String bank_name;private Boolean need_branch;private String account_bank;}
@Getter
@Setter
@NoArgsConstructor
public class BankResVo {private List<BankInfoResVo> data;private Integer totalCount;private Integer errcode;private String errmsg;
}
传入小程序全局唯一后台接口调用凭据access_token、银行卡号carNo
将微信接口返回的结果转换成实体类返回到前端
/*** 获取银行信息* @param accessToken 小程序全局唯一后台接口调用凭据* @param cardNo 银行卡号* @return*/
public BankResVo bankInfoRequest(String accessToken, String cardNo) {BankResVo bankResVo = new BankResVo();// 构造请求URLString requestUrl = "=" + accessToken;JSONObject jsonParams = new JSONObject();jsonParams.put("account_number", cardNo);// 创建 CloseableHttpClient 实例CloseableHttpClient httpClient = ateDefault();// 创建 POST 请求HttpPost post = new HttpPost(requestUrl);try {// 设置请求头post.setHeader("Content-Type", "application/json");// 设置请求体StringEntity entity = new String(), ContentType.APPLICATION_JSON);post.setEntity(entity);// 发送请求并获取响应CloseableHttpResponse response = ute(post);int statusCode = StatusLine().getStatusCode();if (statusCode == 200) {// 解析响应HttpEntity responseEntity = Entity();String responseString = String(responseEntity);//log.info("success,return body = " + responseString );// 解析 JSON 响应JSONObject jsonResponse = new JSONObject(responseString);JSONArray data = JSONArray("data");// 将 JSON 数组转换为实体类列表ObjectMapper mapper = new ObjectMapper();List<BankInfoResVo> bankInfoList = String(), new TypeReference<List<BankInfoResVo>>() {});bankResVo.setData(bankInfoList);bankResVo.Int("total_count"));bankResVo.Int("errcode"));bankResVo.String("errmsg"));} else {throw new IOException("request failed");}} catch (IOException e) {e.printStackTrace();}return bankResVo;
}
本文发布于:2024-01-31 22:45:13,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170671231531927.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |