|
@@ -0,0 +1,225 @@
|
|
|
|
|
+package com.qlm.controller.jinzai;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.jfinal.aop.Clear;
|
|
|
|
|
+import com.jfinal.core.Controller;
|
|
|
|
|
+import com.jfinal.kit.HashKit;
|
|
|
|
|
+import com.jfinal.kit.HttpKit;
|
|
|
|
|
+import com.jfinal.kit.PropKit;
|
|
|
|
|
+import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
+import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
+import com.jfinal.weixin.sdk.api.ApiConfig;
|
|
|
|
|
+import com.jfinal.weixin.sdk.api.ApiConfigKit;
|
|
|
|
|
+import com.jfinal.weixin.sdk.api.JsTicket;
|
|
|
|
|
+import com.jfinal.weixin.sdk.api.JsTicketApi;
|
|
|
|
|
+import com.jfinal.weixin.sdk.api.JsTicketApi.JsApiType;
|
|
|
|
|
+import com.qlm.annotation.RequestUrl;
|
|
|
|
|
+import com.qlm.tools.WxUtil;
|
|
|
|
|
+import com.qlm.tools.ip.CityInfo;
|
|
|
|
|
+import com.qlm.tools.ip.IpAddressUtil;
|
|
|
|
|
+
|
|
|
|
|
+@RequestUrl("/mobile")
|
|
|
|
|
+public class MobileController extends Controller{
|
|
|
|
|
+
|
|
|
|
|
+ @Clear
|
|
|
|
|
+ public void trace(){
|
|
|
|
|
+ setJsTicket();
|
|
|
|
|
+ render("/mobile/index.jsp");
|
|
|
|
|
+ }
|
|
|
|
|
+ @Clear
|
|
|
|
|
+ public void search(){
|
|
|
|
|
+ String code = getPara("code");
|
|
|
|
|
+
|
|
|
|
|
+ String latitude = getPara("latitude");
|
|
|
|
|
+
|
|
|
|
|
+ String longitude = getPara("longitude");
|
|
|
|
|
+
|
|
|
|
|
+ CityInfo locationInfo = getInfo(latitude,longitude);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String ipAddress = IpAddressUtil.getIpAddress(getRequest());
|
|
|
|
|
+
|
|
|
|
|
+ CityInfo ipInfo = IpAddressUtil.getCityInfoByMemorySearch(ipAddress);
|
|
|
|
|
+
|
|
|
|
|
+ String ipProvince = "";
|
|
|
|
|
+
|
|
|
|
|
+ String ipCity = "";
|
|
|
|
|
+ if(ipInfo != null){
|
|
|
|
|
+ ipProvince = ipInfo.getProvince();
|
|
|
|
|
+ ipCity = ipInfo.getCity();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if(locationInfo == null){
|
|
|
|
|
+ locationInfo = new CityInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ String locationCity = locationInfo.getCity();
|
|
|
|
|
+ String locationProvince = locationInfo.getProvince();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String compareCity = "";
|
|
|
|
|
+ String compareProvice = "";
|
|
|
|
|
+ if(locationInfo != null){
|
|
|
|
|
+ compareCity = locationInfo.getCity();
|
|
|
|
|
+ compareProvice = locationInfo.getProvince();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(WxUtil.isNull(compareCity)){
|
|
|
|
|
+ compareCity = ipCity;
|
|
|
|
|
+ compareProvice = ipProvince;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean status = false;
|
|
|
|
|
+ String msg ="";
|
|
|
|
|
+
|
|
|
|
|
+ Record searchInfo = new Record();
|
|
|
|
|
+ Long searchatCount = Db.queryLong("select count(*) from t_jz_searchrecord where child_code = ?",code);
|
|
|
|
|
+
|
|
|
|
|
+ if(searchatCount == null){
|
|
|
|
|
+ searchatCount = 0L;
|
|
|
|
|
+ }
|
|
|
|
|
+ searchatCount++;
|
|
|
|
|
+ searchInfo.set("child_code", code).set("count", searchatCount).set("create_time", new Date())
|
|
|
|
|
+ .set("ip_addr", ipProvince+ipCity)
|
|
|
|
|
+ .set("ip", ipAddress).set("location", locationProvince+locationCity);
|
|
|
|
|
+ Record result = new Record();
|
|
|
|
|
+ boolean cuan = true;
|
|
|
|
|
+ Record jinzai_upload_child = Db.findFirst("select * from jinzai_upload_child where child_code = ?",code);
|
|
|
|
|
+ if(jinzai_upload_child!=null){
|
|
|
|
|
+ String master_code = jinzai_upload_child.getStr("master_code");
|
|
|
|
|
+ Record masterInfo = Db.findFirst("select * from jinzai_upload_master where id = ?",master_code);
|
|
|
|
|
+
|
|
|
|
|
+ String pinxiang = masterInfo.getStr("pinxiang");
|
|
|
|
|
+ result.set("pinxiang", pinxiang);
|
|
|
|
|
+ searchInfo.set("product_name", pinxiang);
|
|
|
|
|
+ if(!WxUtil.isNull(master_code)){
|
|
|
|
|
+ status = true;
|
|
|
|
|
+ Record fahuoInfo = Db.findFirst("select * from deliveryorders where CaseCode =?",master_code);
|
|
|
|
|
+ if(fahuoInfo != null){
|
|
|
|
|
+ String CustomerNo = fahuoInfo.getStr("CustomerNo");
|
|
|
|
|
+
|
|
|
|
|
+ String ProductName = fahuoInfo.getStr("ProductName");
|
|
|
|
|
+
|
|
|
|
|
+ Record jxsInfo = Db.findFirst("select * from jinzai_jxs_area where code = ?",CustomerNo);
|
|
|
|
|
+ if(jxsInfo != null){
|
|
|
|
|
+ String saleCity = jxsInfo.getStr("city");
|
|
|
|
|
+ String saleProvince = jxsInfo.getStr("province");
|
|
|
|
|
+
|
|
|
|
|
+ if(saleCity.equals(compareCity)){
|
|
|
|
|
+ cuan = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ result.set("saleLocation", saleProvince+saleCity);
|
|
|
|
|
+
|
|
|
|
|
+ searchInfo.set("kehu", saleProvince+saleCity);
|
|
|
|
|
+ result.set("fahuoInfo", fahuoInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(cuan){
|
|
|
|
|
+ searchInfo.set("status", 0);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ searchInfo.set("status", 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ Db.save("t_jz_searchrecord", searchInfo);
|
|
|
|
|
+ result.set("status", status).set("msg", msg).set("cuan", cuan).set("location", compareProvice+compareCity);
|
|
|
|
|
+ renderJson(result);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static CityInfo getInfo(String latitude,String longitude){
|
|
|
|
|
+ if(latitude == null || longitude == null){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String location = latitude+","+longitude;
|
|
|
|
|
+ String key = "HTABZ-CBHRQ-WXT5C-BWAGZ-ARXY3-QMB5N";
|
|
|
|
|
+ String url = "https://apis.map.qq.com/ws/geocoder/v1/?location="+location+"&key="+key+"&get_poi=0";
|
|
|
|
|
+ System.out.println(url);
|
|
|
|
|
+ String xmlStr = HttpKit.get(url);
|
|
|
|
|
+ JSONObject parseObject = JSONObject.parseObject(xmlStr);
|
|
|
|
|
+ String message = parseObject.getString("message");
|
|
|
|
|
+
|
|
|
|
|
+ if("Success".equals(message)){
|
|
|
|
|
+ JSONObject result = parseObject.getJSONObject("result");
|
|
|
|
|
+ JSONObject adInfo = result.getJSONObject("ad_info");
|
|
|
|
|
+ String province = adInfo.getString("province");
|
|
|
|
|
+ String city = adInfo.getString("city");
|
|
|
|
|
+ CityInfo ipInfo = new CityInfo();
|
|
|
|
|
+ ipInfo.setCity(city);
|
|
|
|
|
+ ipInfo.setProvince(province);
|
|
|
|
|
+ return ipInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
|
+ CityInfo info = getInfo(30.59276+"",114.30525+"");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setJsTicket() {
|
|
|
|
|
+ ApiConfigKit.setThreadLocalApiConfig(getApiConfig());
|
|
|
|
|
+ JsTicket jsApiTicket = JsTicketApi.getTicket(JsApiType.jsapi);
|
|
|
|
|
+ String ticket = jsApiTicket.getTicket();
|
|
|
|
|
+ String nonce_str = create_nonce_str();
|
|
|
|
|
+ // 注意 URL 一定要动态获取,不能 hardcode.
|
|
|
|
|
+ String authoUrl = PropKit.get("authoUrl");
|
|
|
|
|
+ String url = authoUrl // 项目名称
|
|
|
|
|
+ + getRequest().getServletPath();// 请求页面或其他地址
|
|
|
|
|
+ String qs = getRequest().getQueryString(); // 参数
|
|
|
|
|
+ if (qs != null) {
|
|
|
|
|
+ url = url + "?" + (getRequest().getQueryString());
|
|
|
|
|
+ }
|
|
|
|
|
+ String timestamp = create_timestamp();
|
|
|
|
|
+ // 这里参数的顺序要按照 key 值 ASCII 码升序排序
|
|
|
|
|
+ //注意这里参数名必须全部小写,且必须有序
|
|
|
|
|
+ String str = "jsapi_ticket=" + ticket +
|
|
|
|
|
+ "&noncestr=" + nonce_str +
|
|
|
|
|
+ "×tamp=" + timestamp +
|
|
|
|
|
+ "&url=" + url;
|
|
|
|
|
+ String signature = HashKit.sha1(str);
|
|
|
|
|
+ setAttr("appId", ApiConfigKit.getApiConfig().getAppId());
|
|
|
|
|
+ setAttr("nonceStr", nonce_str);
|
|
|
|
|
+ setAttr("timestamp", timestamp);
|
|
|
|
|
+ setAttr("url", url);
|
|
|
|
|
+ setAttr("signature", signature);
|
|
|
|
|
+ setAttr("jsapi_ticket", ticket);
|
|
|
|
|
+ }
|
|
|
|
|
+ private static String create_timestamp() {
|
|
|
|
|
+ return Long.toString(System.currentTimeMillis() / 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String create_nonce_str() {
|
|
|
|
|
+ return UUID.randomUUID().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public ApiConfig getApiConfig() {
|
|
|
|
|
+ ApiConfig ac = new ApiConfig();
|
|
|
|
|
+ // 配置微信 API 相关常量
|
|
|
|
|
+ ac.setToken("1");
|
|
|
|
|
+ ac.setAppId(PropKit.get("appid"));
|
|
|
|
|
+ ac.setAppSecret(PropKit.get("appsecret"));
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 是否对消息进行加密,对应于微信平台的消息加解密方式: 1:true进行加密且必须配置 encodingAesKey
|
|
|
|
|
+ * 2:false采用明文模式,同时也支持混合模式
|
|
|
|
|
+ */
|
|
|
|
|
+ ac.setEncryptMessage(PropKit.getBoolean("encryptMessage", false));
|
|
|
|
|
+ ac.setEncodingAesKey(PropKit.get("encodingAesKey",
|
|
|
|
|
+ "setting it in config file"));
|
|
|
|
|
+ return ac;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|