|
@@ -0,0 +1,123 @@
|
|
|
|
|
+package com.happy.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
|
+import com.happy.Model.Admin;
|
|
|
|
|
+import com.happy.Model.AdminManager;
|
|
|
|
|
+import com.happy.Model.app.News;
|
|
|
|
|
+import com.happy.Model.weixin.CodeEntity;
|
|
|
|
|
+import com.happy.Model.weixin.WechatResult;
|
|
|
|
|
+import com.happy.common.http.Get_airticle;
|
|
|
|
|
+import com.happy.common.model.airticle.Item_content;
|
|
|
|
|
+import com.happy.common.util.WechatUtil;
|
|
|
|
|
+import com.happy.dao.AppDao;
|
|
|
|
|
+import com.happy.service.AppService;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Service("AppService")
|
|
|
|
|
+public class AppImplService implements AppService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ public AppDao appDao;
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+ // 返回参数
|
|
|
|
|
+ return entity;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public JSONObject getGCodeInfo(String code){
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ JSONObject wx = WechatUtil.getGOpenId(code);
|
|
|
|
|
+ // json数据转换成字符串
|
|
|
|
|
+ assert wx != null;
|
|
|
|
|
+ WechatResult result = new Gson().fromJson(wx.toString(), WechatResult.class);
|
|
|
|
|
+ String openid = result.getOpenid();
|
|
|
|
|
+ String access_token = result.getAccess_token();
|
|
|
|
|
+ jsonObject.put("openid",openid);
|
|
|
|
|
+ jsonObject.put("token",access_token);
|
|
|
|
|
+ return jsonObject;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 登录
|
|
|
|
|
+ public Admin login(String admin_name, String password){
|
|
|
|
|
+ return appDao.login(admin_name, password);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Admin queryByOpenid(String openid){
|
|
|
|
|
+ return appDao.queryByOpenid(openid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Admin queryByNameAndOpenid(String admin_name,String openid){
|
|
|
|
|
+ return appDao.queryByNameAndOpenid(admin_name, openid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int updateOpenid(String openid,String admin_name){
|
|
|
|
|
+ return appDao.updateOpenid(openid, admin_name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int updateOpenidNull(String openid){
|
|
|
|
|
+ return appDao.updateOpenidNull(openid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**********************
|
|
|
|
|
+ * ********商户绑定**********
|
|
|
|
|
+ * ********************/
|
|
|
|
|
+ public AdminManager login_ma(String admin_name, String password){
|
|
|
|
|
+ return appDao.login_ma(admin_name, password);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public AdminManager queryMaByOpenid(String openid){
|
|
|
|
|
+ return appDao.queryMaByOpenid(openid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public AdminManager queryMaByNameAndOpenid(String admin_name,String openid){
|
|
|
|
|
+ return appDao.queryMaByNameAndOpenid(admin_name, openid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int updateMaOpenid(String openid,String admin_name){
|
|
|
|
|
+ return appDao.updateMaOpenid(openid, admin_name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int updateMaOpenidNull(String openid){
|
|
|
|
|
+ return appDao.updateMaOpenidNull(openid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int insertNews(News news){
|
|
|
|
|
+ return appDao.insertNews(news);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public News queryByTit(String title){
|
|
|
|
|
+ return appDao.queryByTit(title);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<Item_content> getNews(int page, int rows) throws Exception {
|
|
|
|
|
+ return Get_airticle.get(page,rows);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<News> queryNewPage(int page, int rows, String sqlx){
|
|
|
|
|
+ return appDao.queryNewPage(page, rows, sqlx);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int queryNewTotal(String sqlx){
|
|
|
|
|
+ return appDao.queryNewTotal(sqlx);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|