|
|
@@ -0,0 +1,33 @@
|
|
|
+package com.happy.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.happy.Model.weixin.CodeEntity;
|
|
|
+import com.happy.common.util.WechatUtil;
|
|
|
+import com.happy.service.AppService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+@Service("AppService")
|
|
|
+public class AppImplService implements AppService {
|
|
|
+
|
|
|
+ public CodeEntity getCodeInfo(String code){
|
|
|
+ CodeEntity entity = new CodeEntity();
|
|
|
+ JSONObject wx = WechatUtil.getOpenId(code);
|
|
|
+ // json数据转换成字符串
|
|
|
+ assert wx != null;
|
|
|
+ String openid = wx.get("openid").toString();
|
|
|
+ String sessionkey = wx.get("session_key").toString();
|
|
|
+ // 当主体账户绑定小程序后就可以获取到,未绑定无法获取
|
|
|
+ String unionId="";
|
|
|
+ if(wx.get("unionid")!=null){
|
|
|
+ unionId=wx.get("unionid").toString();
|
|
|
+ }
|
|
|
+ entity.setOpenid(openid);
|
|
|
+ entity.setSessionkey(sessionkey);
|
|
|
+ entity.setUnionid(unionId);
|
|
|
+ // 是否需要获取手机号,true需要
|
|
|
+ entity.setFlagPhone(true);
|
|
|
+ System.out.println("openid:"+openid+",session_key:"+sessionkey+",unionid:"+unionId);
|
|
|
+ // 返回参数
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+}
|