| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- package com.qlm.controller.jinzai;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- 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.log.Log;
- 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","");
-
- code = code.toUpperCase();
-
- 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;
- boolean isThird = false;
- if(code.length() ==14){//易码
- try{
- isThird = true;
- String jsonData = HttpKit.get("http://saas.ymbs.com.cn/ccn/sk-warehouse-out/scanCode/"+code);
- JSONObject parseObject = JSONObject.parseObject(jsonData);
-
- JSONObject data = parseObject.getJSONObject("data");
-
- String distributorName = data.getString("distributorName");
-
- String operateDate = data.getString("operateDate");
- String salesTerritory = data.getString("salesTerritory");
-
-
- String productName = data.getString("productName");
-
- result.set("pinxiang", productName);
- Record fahuoInfo = new Record();
- fahuoInfo.set("DeliveryTime", operateDate).set("CustomerName", distributorName);
-
- Record jxsInfo = Db.findFirst("select * from jinzai_jxs_area where jxs = ?",distributorName);
-
- 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);
- status = true;
- }
- }catch(Exception e){
- Log.info("em接口查询失败,"+code);
- e.printStackTrace();
- }
-
- }else if(code.length() == 21){
- try{
- isThird = true;
- Map<String,String> header =new HashMap<String,String>();
- header.put("content-type", "application/json;charset=UTF-8");
- JSONObject obj = new JSONObject();
- obj.put("code", code);
- obj.put("latitude", 34.16559);
-
- obj.put("longitude", 112.824936);
- String jsonData = HttpKit.post("https://jinzai.oklinklink.com/api/trace/inspect/customer/find",obj.toJSONString(),header);
- JSONObject parseObject = JSONObject.parseObject(jsonData);
-
- JSONObject data = parseObject.getJSONObject("data");
-
- String distributorName = data.getString("bizCorpName");
-
- String operateDate = data.getString("billTime");
-
-
- String productName = data.getString("productName");
-
- result.set("pinxiang", productName);
- Record fahuoInfo = new Record();
- fahuoInfo.set("DeliveryTime", operateDate).set("CustomerName", distributorName);
-
- Record jxsInfo = Db.findFirst("select * from jinzai_jxs_area where jxs = ?",distributorName);
-
- 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);
- status = true;
- }
- }catch(Exception e){
- Log.info("em接口查询失败,"+code);
- e.printStackTrace();
- }
-
-
- }else if(code.length() == 22){
- String master_code = 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);
- }
-
- }
-
-
- }
- }
-
- else{
- 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);
- }
- if(!isThird){
- Db.save("t_jz_searchrecord", searchInfo);
- }
-
- result.set("status", status).set("msg", msg).set("cuan", cuan).set("location", compareProvice+compareCity);
- renderJson(result);
-
- }
-
-
- /**
- * 1是我们自己的
- * 2是易码
- * 3是爱创
- * @param code
- * @return
- */
- private int codeType(String code) {
- if(code.length() == 14){
- return 3;
- }
- if(code.length() == 22){
-
- }
- return 0;
- }
- 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;
- }
-
- }
|