diff --git a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java index f3ccf34..a10a314 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java @@ -7,17 +7,19 @@ import com.sincere.wechatbusiness.dto.BaseDto; import com.sincere.wechatbusiness.dto.ChannelDto; import com.sincere.wechatbusiness.model.*; import com.sincere.wechatbusiness.service.*; +import com.sincere.wechatbusiness.utils.HttpClientUtils; import com.sincere.wechatbusiness.utils.Page; +import com.sincere.wechatbusiness.utils.TokenUtils; import io.swagger.annotations.ApiOperation; -import org.bouncycastle.jcajce.provider.symmetric.util.BaseWrapCipher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import java.io.BufferedReader; -import java.io.InputStreamReader; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.List; @@ -43,6 +45,12 @@ public class ChannelController { @Autowired CatalogContentService catalogContentService; + @Autowired + AgentService agentService; + + private String domain="https://mytest.myjxt.com:51314"; +// private String domain="https://proxy.shunzhi.net:51314"; + @RequestMapping(value = "GetChannelList",method = RequestMethod.POST) @ApiOperation(value = "获取渠道商列表") public BaseDto> GetChannelList(@RequestBody ChannelDto channelDto){ @@ -58,7 +66,7 @@ public class ChannelController { @ApiOperation(value = "获取代理商品列表") public BaseDto> GetPackageList(){ BaseDto> result=new BaseDto<>(); - String r=Get("https://mytest.myjxt.com:51314/University/getPackageList",""); + String r=Get(domain+"/University/getPackageList",""); JSONObject jsonObject= JSONObject.parseObject(r); String data = jsonObject.getString("data"); List list=JSON.parseObject(data,new TypeReference>(){}); @@ -201,7 +209,7 @@ public class ChannelController { catalog.setChannelId(channelId); catalog.setSort(sort); catalog=catalogService.getDetail(catalog); - catalog.setCatalogContentList(catalogContentService.getList(catalog.getId())); + if(catalog!=null) catalog.setCatalogContentList(catalogContentService.getList(catalog.getId())); result.setData(catalog); return result; } @@ -241,6 +249,181 @@ public class ChannelController { return new BaseDto(); } + @RequestMapping(value = "GetAgentList",method = RequestMethod.GET) + @ApiOperation(value = "获取推广代理列表") + public BaseDto> GetAgentList(int id){ + BaseDto> result=new BaseDto<>(); + result.setData(agentService.getList(id)); + return result; + } + + @RequestMapping(value = "AddAgent",method = RequestMethod.POST) + @ApiOperation(value = "新增推广代理") + public BaseDto AddAgent(@RequestBody Agent agent){ + agentService.insert(agent); + return new BaseDto(); + } + + @RequestMapping(value = "UpdateAgent",method = RequestMethod.POST) + @ApiOperation(value = "编辑推广代理") + public BaseDto UpdateAgent(@RequestBody Agent agent){ + agentService.update(agent); + return new BaseDto(); + } + + @RequestMapping(value = "DeleteAgent",method = RequestMethod.GET) + @ApiOperation(value = "删除推广代理") + public BaseDto DeleteAgent(int id){ + agentService.deleteAgent(id); + return new BaseDto(); + } + + @RequestMapping(value = "GetCatalogList",method = RequestMethod.GET) + @ApiOperation(value = "获取栏目列表") + public BaseDto> GetCatalogList(int id){ + BaseDto> result=new BaseDto<>(); + result.setData(catalogService.getList(id)); + return result; + } + + @RequestMapping(value = "GetCatalogContByDate",method = RequestMethod.GET) + @ApiOperation(value ="根据日期获取栏目内容" ) + public BaseDto> GetCatalogContByDate(int catalogId,String date){ + BaseDto> result=new BaseDto<>(); + result.setData(catalogContentService.getListByDate(catalogId,date)); + return result; + } + + @RequestMapping(value = "GetChannelProduct",method = RequestMethod.GET) + @ApiOperation(value = "获取代理商品详情") + public BaseDto GetChannelProduct(int id){ + BaseDto result=new BaseDto<>(); + result.setData(channelProductService.getDetail(id)); + return result; + } + + @RequestMapping(value = "GetDiscountPackage",method = RequestMethod.GET) + @ApiOperation(value = "获取商品详情") + public BaseDto GetDiscountPackage(int id){ + BaseDto result=new BaseDto<>(); + String r=Get(domain+"/University/getPackageById","id="+id); + JSONObject jsonObject= JSONObject.parseObject(r); + String data = jsonObject.getString("data"); + DiscountPackage model=JSON.parseObject(data,new TypeReference(){}); + result.setData(model); + return result; + } + + @RequestMapping(value = "GetWxSign",method = RequestMethod.GET) + @ApiOperation(value = "获取微信分享签名") + public BaseDto GetWxSign(String url){ + BaseDto result=new BaseDto<>(); + String r=Get("http://114.55.30.100:1111/api/UserRegisterApp/GetWxShareSign","url="+url); + JSONObject jsonObject= JSONObject.parseObject(r); + String data = jsonObject.getString("result"); + WxSign wxSign=JSON.parseObject(data,new TypeReference(){}); + result.setData(wxSign); + return result; + } + + @RequestMapping(value = "AddVerificationCode",method = RequestMethod.GET) + @ApiOperation(value = "获取验证码") + public BaseDto AddVerificationCode(String mobile){ + Get(domain+"/h5/MyVoluntary/AddVerificationCode","code=206&mobile="+mobile+"&type=1"); + return new BaseDto(); + } + + @RequestMapping(value = "CheckCodeIsRight",method = RequestMethod.GET) + @ApiOperation(value = "判断验证码是否正确") + public BaseDto CheckCodeIsRight(String mobile, String captcha){ + BaseDto result=new BaseDto(); + String r=Get(domain+"/h5/MyVoluntary/CheckCodeIsRight","mobile="+mobile+"&captcha="+captcha); + JSONObject jsonObject= JSONObject.parseObject(r); + result.setSuccess(jsonObject.getString("success")=="true"?true:false); + result.setMessage(jsonObject.getString("message")); + return result; + } + + @RequestMapping(value = "AdminLogin",method = RequestMethod.GET) + @ApiOperation(value = "管理员登录") + public BaseDto AdminLogin(String mobile){ + BaseDto result=new BaseDto(); + Manager manager=channelService.getManagerDetail(mobile); + if(manager==null){ + result.setSuccess(false); + result.setMessage("账号不存在!"); + } + Log log=new Log(); + log.setOperation("账号登录"); + log.setMobile(mobile); + channelService.insertLog(log); + result.setData(TokenUtils.buildToken(mobile)); + return result; + } + + @RequestMapping(value = "IsDianXin",method = RequestMethod.GET) + @ApiOperation(value = "判断是否是电信用户") + public BaseDto> IsDianXin(String mobile,int productId){ + BaseDto> result=new BaseDto(); + String r=Get(domain+"/admin/Voluntary/GetAccount","mobile="+mobile); + JSONObject jsonObject= JSONObject.parseObject(r); + String data = jsonObject.getString("data"); + if(data==null){ + result.setSuccess(false); + result.setMessage("非VIP邀请号码"); + } + else { + Get(domain+"/h5/MyVoluntary/AddVerificationCode","code=206&mobile="+mobile+"&type=1"); + String re=Get(domain+"/University/getMyCouponDetail","mobile="+mobile+"&type="+productId); + JSONObject jsonObject1= JSONObject.parseObject(re); + String data1 = jsonObject1.getString("data"); + result.setData(JSON.parseObject(data1,new TypeReference>(){})); + } + return result; + } + + @RequestMapping(value = "GetAddOrderDetail",method = RequestMethod.POST) + @ApiOperation(value = "生成预支付订单并返回详情") + public BaseDto> GetAddOrderDetail(@RequestBody Order order) { + BaseDto> result=new BaseDto<>(); + JSONObject object = new JSONObject(); + object.put("account",order.getAccount()); + object.put("expert_id",0); + object.put("paymoney",order.getPaymoney()); + object.put("payway",2); + object.put("product_detail","升学汇产品-代理商"); + object.put("product_id",order.getProduct_id()); + object.put("product_name",order.getProduct_name()); + object.put("type",order.getProduct_id()); + object.put("user_name",order.getUser_name()); + object.put("buycount",0); + object.put("score_id",0); + JSONObject jsonObject = HttpClientUtils.httpPostJson(domain+"/University/GetAddOrderDetail",object.toJSONString()); + String data = jsonObject.getString("data"); + result.setData(JSON.parseObject(data,new TypeReference>(){})); + return result; + } + + @RequestMapping(value = "WxPay",method = RequestMethod.POST) + @ApiOperation(value = "微信支付") + public BaseDto WxPay(@RequestBody WxPay pay){ + BaseDto result = new BaseDto(); + JSONObject object = new JSONObject(); + object.put("attach",pay.getAttach()); + object.put("notify_url",domain+"/Payment/WXPayBack"); + object.put("outTradeNo",pay.getOutTradeNo()); + object.put("payType",2); + object.put("payWay",2); + object.put("productId",pay.getProductId()); + object.put("subject",pay.getSubject()); + object.put("totalFee",pay.getTotalFee()); + object.put("coupon_num",pay.getCoupon_num()); + JSONObject jsonObject = HttpClientUtils.httpPostJson(domain+"/Payment/WxPay",object.toJSONString()); + String data = jsonObject.getString("data"); + result.setData(JSON.parseObject(data,new TypeReference(){})); + return result; + } + public String Get(String url, String param) { String result = ""; BufferedReader in = null; @@ -285,4 +468,86 @@ public class ChannelController { } return result; } + + public String Post(String httpUrl, String param) + { + HttpURLConnection connection = null; + InputStream is = null; + OutputStream os = null; + BufferedReader br = null; + String result = null; + try { + URL url = new URL(httpUrl); + // 通过远程url连接对象打开连接 + connection = (HttpURLConnection) url.openConnection(); + // 设置连接请求方式 + connection.setRequestMethod("POST"); + // 设置连接主机服务器超时时间:15000毫秒 + connection.setConnectTimeout(15000); + // 设置读取主机服务器返回数据超时时间:60000毫秒 + connection.setReadTimeout(60000); + + // 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true + connection.setDoOutput(true); + // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 + connection.setDoInput(true); + // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 + connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0"); + + // 通过连接对象获取一个输出流 + os = connection.getOutputStream(); + // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 + os.write(param.getBytes()); + // 通过连接对象获取一个输入流,向远程读取 + if (connection.getResponseCode() == 200) { + + is = connection.getInputStream(); + // 对输入流对象进行包装:charset根据工作项目组的要求来设置 + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + + StringBuffer sbf = new StringBuffer(); + String temp = null; + // 循环遍历一行一行读取数据 + while ((temp = br.readLine()) != null) { + sbf.append(temp); + sbf.append("\r\n"); + } + result = sbf.toString(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // 关闭资源 + if (null != br) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (null != os) { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (null != is) { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + // 断开与远程地址url的连接 + connection.disconnect(); + } + return result; + } + } diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/AgentMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/AgentMapper.java new file mode 100644 index 0000000..6847e75 --- /dev/null +++ b/src/main/java/com/sincere/wechatbusiness/mapper/AgentMapper.java @@ -0,0 +1,15 @@ +package com.sincere.wechatbusiness.mapper; + +import com.sincere.wechatbusiness.model.Agent; + +import java.util.List; + +public interface AgentMapper { + List getList(int id); + + int insert(Agent agent); + + int update(Agent agent); + + int deleteAgent(int id); +} diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/CatalogContentMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/CatalogContentMapper.java index e613439..2bf56aa 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/CatalogContentMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/CatalogContentMapper.java @@ -1,6 +1,7 @@ package com.sincere.wechatbusiness.mapper; import com.sincere.wechatbusiness.model.CatalogContent; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -12,4 +13,6 @@ public interface CatalogContentMapper { int update(CatalogContent catalogContent); int deleteCatalogContent(int id); + + List getListByDate(@Param("catalogId") int catalogId,@Param("date") String date,@Param("state") int state); } diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/CatalogMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/CatalogMapper.java index 096c4c2..8ba6c7f 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/CatalogMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/CatalogMapper.java @@ -2,10 +2,14 @@ package com.sincere.wechatbusiness.mapper; import com.sincere.wechatbusiness.model.Catalog; +import java.util.List; + public interface CatalogMapper { Catalog getDetail(Catalog catalog); int insert(Catalog catalog); int update(Catalog catalog); + + List getList(int id); } diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java index 449379d..cdba067 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java @@ -1,8 +1,6 @@ package com.sincere.wechatbusiness.mapper; -import com.sincere.wechatbusiness.model.Area; -import com.sincere.wechatbusiness.model.Channel; -import com.sincere.wechatbusiness.model.Template; +import com.sincere.wechatbusiness.model.*; import java.util.List; @@ -26,4 +24,8 @@ public interface ChannelMapper { List getArea(String areaCode); List