公众号获取用户信息接口

This commit is contained in:
kuang.yife 2023-10-08 23:08:27 +08:00
parent 8e661f0211
commit 1dd6bc0065
3 changed files with 26 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import com.ghy.common.enums.OrderStatus;
import com.ghy.common.exception.ServiceException;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.StringUtils;
import com.ghy.common.utils.WechatMsgUtils;
import com.ghy.common.utils.WxUtils;
import com.ghy.common.utils.http.HttpUtils;
import com.ghy.customer.domain.Customer;
@ -184,6 +185,23 @@ public class WxController extends BaseController {
}
String data = HttpUtils.sendGet(url, null);
JSONObject result = JSONObject.parseObject(data);
// 如果是师傅端,需要调用公众号的获取用户列表接口 -- 遍历列表去找到unionId和openid关联并入库
if(!"customer".equals(from)){
String openid = result.getString("openid");
String unionId = result.getString("unionid");
// 查询openid是否入库已经入库则不管
Worker param = new Worker();
param.setOpenId(openid);
Worker worker = workerService.selectByOpenId(param);
if(worker != null && StringUtils.isEmpty(worker.getWxOpenId())){
// 公众号token
String wxToken = WechatMsgUtils.getToken();
String wxUserOpenidList = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/user/get?access_token="+wxToken+"&next_openid=NEXT_OPENID");
logger.info("公众号获取的用户列表集合:{}", wxUserOpenidList);
JSONObject wxOpenidJson = JSONObject.parseObject(wxUserOpenidList);
}
}
return AjaxResult.success(result);
}

View File

@ -38,6 +38,12 @@ public class Worker extends BaseEntity {
@Excel(name = "微信open_id", cellType = Excel.ColumnType.STRING)
private String openId;
@Excel(name = "微信union_id", cellType = Excel.ColumnType.STRING)
private String unionId;
@Excel(name = "公众号open_id", cellType = Excel.ColumnType.STRING)
private String wxOpenId;
@Excel(name = "支付宝账号")
private String alipayAccount;

View File

@ -8,6 +8,8 @@
<result property="account" column="account"/>
<result property="phone" column="phone"/>
<result property="openId" column="open_id"/>
<result property="unionId" column="union_id"/>
<result property="wxUnionId" column="wx_open_id"/>
<result property="alipayAccount" column="alipay_account"/>
<result property="alipayName" column="alipay_name"/>
<result property="password" column="password"/>