整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          手擼的一個快遞查詢系統,竟然閱讀量過1.8w

          手擼的一個快遞查詢系統,竟然閱讀量過1.8w


          、目的

          做這個項目的初衷是因為我去年在微信賣老家水果,好多朋友下單后都問我快遞單號,每天發貨后我都要挨個甄別這個人是哪個快遞信息,很麻煩一部小心就搞錯了。基于這件小事我有了自助快遞查詢的這個想法。將發貨的快遞信息導入到我的系統里,用戶訪問我的系統,通過輸入手機號就可以查看自己的快遞物流信息。 項目是去年8月寫的,一直擱淺在哪,最近無意間翻看我發的那篇文章自助快遞單號查詢閱讀量竟然都1.8w了,有圖有真相。

          這著實讓我很震驚,看來自助快遞查詢這塊確實是個熱點。今天我就講一下我手擼的快遞查詢系統。

          二、開發

          項目地址:github.com/hellowHuaai… 有興趣的可以直接下載源碼,覺得項目不錯的伙伴記得點個star,謝謝啦!

          2.1技術棧

          項目涉及到的技術棧有:

          • SpringBoot: 一款 Java 微服務框架。Spring boot 是 Spring 家族中的一個新框架,它用來簡化 Spring 應用程序的創建和開發。
          • Mybitas: 一款ORM框架,即對象關系映射。ORM框架的作用是把持久化對象的保存、修改、刪除等操作,轉換成對數據庫的操作。
          • Jquery:一個輕量級的寫的少,做的多的 JavaScript 函數庫。
          • Bootstrap:Bootstrap 是一個用于快速開發 Web 應用程序和網站的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的。

          2.2后端開發

          創建entity 創建快遞單實體類,屬性包括id,用戶名(userName),電話(phone),快遞單號(kuaidiNo),快遞公司(company),數據創建時間(createTime)。代碼如下:

          @Data
          @Builder
          public class KuaiDi {
              private Integer id;
              /* 收件人姓名 */
              private String userName;
              /**收件人電話*/
              private String phone;
              /* 快遞單號*/
              private String kuaidiNo;
              /*快遞公司名稱(拼音)*/
              private String company;
              /*訂單創建時間*/
              private Date createTime;
              
              public KuaiDi(Integer id, String userName, String phone, String kuaidiNo, String company, Date createTime) {
                  this.id=id;
                  this.userName=userName;
                  this.phone=phone;
                  this.kuaidiNo=kuaidiNo;
                  this.company=company;
                  this.createTime=createTime;
              }
              public KuaiDi(Integer id, String userName, String phone, String kuaidiNo, String company) {
                  this.id=id;
                  this.userName=userName;
                  this.phone=phone;
                  this.kuaidiNo=kuaidiNo;
                  this.company=company;
              }
          }

          service,mapper是常規的增刪查改操作,就是保存快遞的基本信息在數據庫中,并可以對數據進行簡單的維護功能。詳細可參考項目源碼。接下來看核心代碼。

          查詢快遞信息 快遞的基本信息存入數據庫,然后就是通過這些信息查詢快遞的詳細物流信息。這里我做過很多嘗試,想直接調用一些快遞公司的快遞信息查詢接口,但是都發現接口都有session,當session失效后就無法查詢到數據或者就查詢到的數據不正確。最終在網上找到一種付費的方案,使用快遞100接口。www.kuaidi100.com/ 查詢快遞的demo代碼如下:

          public class SynQueryDemo {
          
          	/**
          	 * 實時查詢請求地址
          	 */
          	private static final String SYNQUERY_URL="http://poll.kuaidi100.com/poll/query.do";
          	
          	private String key;			//授權key
          	private String customer;	//實時查詢公司編號
          
          	public SynQueryDemo(String key, String customer) {
          		this.key=key;
          		this.customer=customer;
          	}
          	
          	/**
          	 * 實時查詢快遞單號
          	 * @param com			快遞公司編碼
          	 * @param num			快遞單號
          	 * @param phone			手機號
          	 * @param from			出發地城市
          	 * @param to			目的地城市
          	 * @param resultv2		開通區域解析功能:0-關閉;1-開通
          	 * @return
          	 */
          	public String synQueryData(String com, String num, String phone, String from, String to, int resultv2) {
          
          		StringBuilder param=new StringBuilder("{");
          		param.append("\"com\":\"").append(com).append("\"");
          		param.append(",\"num\":\"").append(num).append("\"");
          		param.append(",\"phone\":\"").append(phone).append("\"");
          		param.append(",\"from\":\"").append(from).append("\"");
          		param.append(",\"to\":\"").append(to).append("\"");
          		if(1==resultv2) {
          			param.append(",\"resultv2\":1");
          		} else {
          			param.append(",\"resultv2\":0");
          		}
          		param.append("}");
          		
          		Map<String, String> params=new HashMap<String, String>();
          		params.put("customer", this.customer);
          		String sign=MD5Utils.encode(param + this.key + this.customer);
          		params.put("sign", sign);
          		params.put("param", param.toString());
          		
          		return this.post(params);
          	}
          	
          	/**
          	 * 發送post請求
          	 */
          	public String post(Map<String, String> params) {
          		StringBuffer response=new StringBuffer("");
          		
          		BufferedReader reader=null;
          		try {
          			StringBuilder builder=new StringBuilder();
          			for (Map.Entry<String, String> param : params.entrySet()) {
          				if (builder.length() > 0) {
          					builder.append('&');
          				}
          				builder.append(URLEncoder.encode(param.getKey(), "UTF-8"));
          				builder.append('=');
          				builder.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
          			}
          			byte[] bytes=builder.toString().getBytes("UTF-8");
          
          			URL url=new URL(SYNQUERY_URL);
          			HttpURLConnection conn=(HttpURLConnection) url.openConnection();
          			conn.setConnectTimeout(3000);
          			conn.setReadTimeout(3000);
          			conn.setRequestMethod("POST");
          			conn.setRequestProperty("accept", "*/*");
                      conn.setRequestProperty("connection", "Keep-Alive");
          			conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          			conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
          			conn.setDoOutput(true);
          			conn.getOutputStream().write(bytes);
          
          			reader=new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
          			
          			String line="";
                      while ((line=reader.readLine()) !=null) {
                      	response.append(line);
                      }
          		} catch (Exception e) {
          			e.printStackTrace();
          		} finally {
          			try {
          				if (null !=reader) {
          					reader.close();
          				}
          			} catch (IOException e) {
          				e.printStackTrace();
          			}
          		}
          		
          		return response.toString();
          	}
          }

          上面的代碼就是通過java代碼調用kuaidi100的查詢接口,這個查詢接口會通過快遞單號自動識別快遞是屬于哪個快遞公司,然后調用對應快遞公司接口獲取響應數據。付費購買接口使用權其實就是生成一個授權key和實時查詢公司編號customer,在線調用會做身份認證。這樣就可以獲取快遞信息的json數據了。我已經購買了100塊大洋的接口使用權,大家可直接調用快遞查詢接口。

          controller代碼 快遞信息增刪查改的controller就不在列了,這里主要看下我對查詢快遞的接口進行了一次包裝處理。代碼如下:

          @RestController
          public class KuaiDiQueryController {
          
              @Autowired
              private KuaiDiService kuaiDiService;
              @Autowired
              private KuaiDiQueryService kuaiDiQueryService;
          
              /**
               * 返回json數據
               * @param com
               * @param no
               * @return
               */
              @GetMapping("/getKuaiDiInfoByJson")
              @ResponseBody
              public String queryKuadiInfoByJson(String com, String no) {
                  return kuaiDiQueryService.synQueryData(com, no,"", "", "", 0);
              }
          
              @GetMapping("/getKuaiDiInfoByPhone")
              @ResponseBody
              public Response queryKuaidiByPhone(String phone){
                  Response response=new Response();
                  if(StringUtils.isNotEmpty(phone)){
                      List<ResponseData> responseDataList=new ArrayList<>();
                      //  1.通過手機號查詢下面的所有訂單號
                      List<KuaiDi> kuaiDiList=kuaiDiService.getList("", phone);
                      if(!CollectionUtils.isEmpty(kuaiDiList)){
                          kuaiDiList.forEach(kuaiDi -> {
                              //  2.依次查出所有的訂單號
                              String responseDataStr=kuaiDiQueryService.synQueryData(kuaiDi.getCompany(), kuaiDi.getKuaidiNo(),"", "", "", 0);
                              ResponseData responseData=CommonUtils.convertJsonStr2Object(responseDataStr);
                              responseDataList.add(responseData);
                          });
                      }
                      // 3.組裝數據返回給前臺
                      response.setDataList(responseDataList);
                  }
                  return response;
              }
          }

          2.3前端開發

          前端展示主要包括兩個頁面,管理員頁面和客戶頁面。管理員頁面功能包括快遞信息的新增,修改,刪除,分頁查詢,在線快遞物流信息接口。客戶頁面包括快遞信息的分頁查詢和在線快遞物流信息接口。所以主要看一下管理員頁面。

          html頁面 html頁面引入了jQuery和Bootstrap,jQuery已經過時了,但是使用起來還是很方便的。

          <html>
          <head>
            <title>快遞單號查詢</title>
              <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
              <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
              <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
              <script src="https://cdn.bootcss.com/bootbox.js/4.4.0/bootbox.min.js"></script>
              <link href="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.css" rel="stylesheet">
              <script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>
              <script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
            ...
          </head>
          <body>
              <div class="container-fluid">
          
                  <div class="row">
                      <nav class="navbar navbar-inverse navbar-fixed-top">
                          <a class="navbar-brand" href="http://mhtclub.com">我的個人主頁</a>
                          <button class="navbar-toggle" data-toggle="collapse" data-target="#collapseMenu">
                              <span class="icon-bar"></span>
                              <span class="icon-bar"></span>
                              <span class="icon-bar"></span>
                          </button>
                          <div class="collapse navbar-collapse" id="collapseMenu">
                              <ul class="nav navbar-nav">
                                  <li class="nav-li">
                                      <a href="https://github.com/hellowHuaairen/kuaidi" target="_blank">本項目github</a>
                                  </li>
                              </ul>
                          </div>
                      </nav>
                  </div>
          
                  <h1 class="page-header">
                      快遞單號自助查詢
                  </h1>
          
                  <!-- 查詢工具欄 -->
                  <div class="form-inline">
                      <div class="form-group">
                          <label for="queryNameText">收件人姓名:</label>
                          <input id="queryNameText" class="form-control input-sm">
                      </div>
                      <div class="form-group">
                          <label for="queryPhoneText">收件人電話:</label>
                          <input id="queryPhoneText" class="form-control input-sm">
                      </div>
                      <button class="btn btn-primary btn-sm" id="queryBtn">查詢</button>
                      <button class="btn btn-primary btn-sm" id="resetBtn">重置</button>
                      <button class="btn btn-primary btn-sm" id="addBtn">新增</button>
                  </div>
                  <hr>
          
                  <table id="testTable"></table>
          
                  <!-- 查看訂單信息模態窗 -->
                  <div class="modal fade" id="viewModal">
                      <div class="modal-dialog">
                          <div class="modal-content">
                              <div class="modal-header">
                                  <button type="button" class="close" data-dismiss="modal">×</button>
                                  <h4 class="modal-title">訂單信息</h4>
                              </div>
                              <div class="modal-body" id="viewDataList"></div>
                              <div class="modal-footer">
                                  <button class="btn btn-default" data-dismiss="modal">關閉</button>
                              </div>
                          </div>
                      </div>
                  </div>
                  <!-- 新增模態窗 -->
                  <div class="modal fade" id="addModal">
                      <div class="modal-dialog">
                          <div class="modal-content">
                              <div class="modal-header">
                                  <button type="button" class="close" data-dismiss="modal">×</button>
                                  <h4 class="modal-title">新增信息</h4>
                              </div>
                              <div class="modal-body">
                                  <div class="form-inline">
          
                                  </div>
                                  <div class="form-group">
                                      <label for="addNameText">收件人姓名:</label>
                                      <input id="addNameText" class="form-control input-sm">
                                  </div>
                                  <div class="form-group">
                                      <label for="addPhoneText">收件人電話:</label>
                                      <input id="addPhoneText" class="form-control input-sm">
                                  </div>
                                  <div class="form-group">
                                      <label for="addKuaiDiNoText">快遞單號:</label>
                                      <input id="addKuaiDiNoText" class="form-control input-sm">
                                  </div>
                                  <div class="form-group">
                                      <label for="addCompanyText">快遞公司(拼音):</label>
                                      <input id="addCompanyText" class="form-control input-sm">
                                  </div>
                              </div>
                              <div class="modal-footer">
                                  <button class="btn btn-default" data-dismiss="modal">關閉</button>
                                  <button class="btn btn-primary" id="saveAdd">保存</button>
                              </div>
                          </div>
                      </div>
                  </div>
          
                  <!-- 修改模態窗 -->
                  <div class="modal fade" id="modifyModal">
                      <div class="modal-dialog">
                          <div class="modal-content">
                              <div class="modal-header">
                                  <button type="button" class="close" data-dismiss="modal">×</button>
                                  <h4 class="modal-title">修改信息</h4>
                              </div>
                              <div class="modal-body">
                                  <div class="form-inline">
          
                                  </div>
                                  <div class="form-group">
                                      <label for="modifyNameText">收件人姓名:</label>
                                      <input id="modifyNameText" class="form-control input-sm">
                                  </div>
                                  <div class="form-group">
                                      <label for="modifyPhoneText">收件人電話:</label>
                                      <input id="modifyPhoneText" class="form-control input-sm">
                                  </div>
                                  <div class="form-group">
                                      <label for="modifyKuaiDiNoText">快遞單號:</label>
                                      <input id="modifyKuaiDiNoText" class="form-control input-sm">
                                  </div>
                                  <div class="form-group">
                                      <label for="modifyCompanyText">快遞公司(拼音):</label>
                                      <input id="modifyCompanyText" class="form-control input-sm">
                                  </div>
                              </div>
                              <div class="modal-footer">
                                  <button class="btn btn-default" data-dismiss="modal">關閉</button>
                                  <button class="btn btn-primary" id="saveModify">保存</button>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>  <!-- container-fluid -->
          
              <script type="text/javascript" src="js/admin.js"></script>
          </body>
          </html>

          admin.js 這里說明一下前端我引入的jQuery,包括新增,修改,刪除,查詢的功能,查詢事件添加了對電話號碼的必填校驗。

          var $testTable=$('#testTable');
          $testTable.bootstrapTable({
              url: 'getList',
              queryParams: function (params) {
                  return {
                      offset: params.offset,
                      limit: params.limit,
                      userName: $('#queryNameText').val(),
                      phone: $('#queryPhoneText').val()
                  }
              },
              columns: [{
                  field: 'id',
                  title: '編號'
              }, {
                  field: 'userName',
                  title: '收件人姓名'
              }, {
                  field: 'phone',
                  title: '收件人電話'
              },  {
                  field: 'company',
                  title: '快遞公司'
              },{
                  field: 'kuaidiNo',
                  title: '快遞單號',
                  formatter: function (value, row, index) {
                      return [
          				'<a onclick="kuaidiRecordInfo(' + "'" + row.kuaidiNo + "','" + row.company + "')" + '">' + row.kuaidiNo +'</a>',
                      ].join('');
                  },
              }, {
                  formatter: function (value, row, index) {
                      return [
                          '<a href="javascript:modifyKuaiDi(' + row.id + ",'" + row.userName + "'," + row.phone + ",'" + row.kuaidiNo + "'" + ')">' +
                              '<i class="glyphicon glyphicon-pencil"></i>修改' +
                          '</a>',
                          '<a href="javascript:delKuaiDi(' + row.id + ')">' +
                              '<i class="glyphicon glyphicon-remove"></i>刪除' +
                          '</a>'
                      ].join('');
                  },
                  title: '操作'
              }],
              striped: true,
              pagination: true,
              sidePagination: 'server',
              pageSize: 10,
              pageList: [5, 10, 25, 50, 100],
              rowStyle: function (row, index) {
                  var ageClass='';
                  if (row.age < 18) {
                      ageClass='text-danger';
                  }
                  return {classes: ageClass}
              },
          });
          
          // 設置bootbox中文
          bootbox.setLocale('zh_CN');
          
          var titleTip='提示';
          
          function kuaidiRecordInfo(no, company) {
              $('#viewModal').modal('show');
              $.ajax({
                  type:'get',
                  url:'getKuaiDiInfoByJson?com='+ company +'&no=' + no,
                  cache:false,
                  dataType:'json',
                  success:function(result){
                      // 顯示詳細信息 發送請求通過單號
          			$("#viewDataList").empty();
                      console.log(result.data);
                      var dataList=result.data;
                      if(null !=dataList){
          				$("#viewDataList").append('<li class="accordion-navigation"><a href="#kuaidi'+ '">快遞單號:'+ result.nu +'</a><div id="kuaidi'+ '" class="content"></div></li>');
          				$("#kuaidi").append('<section class="result-box"><div id="resultTop" class="flex result-top"><time class="up">時間</time><span>地點和跟蹤進度</span></div><ul id="reordList'+'" class="result-list sortup"></ul></section>');  
                          for(var i=0;i<dataList.length; i++){
                              var kuaiRecodList=dataList[i];
                              if( i==0){
                                  $("#reordList").append('<li class="last finish"><div class="time"> '+ kuaiRecodList.ftime + '</div><div class="dot"></div><div class="text"> '+ kuaiRecodList.context +'</div></li>');
                              }else{
                                  $("#reordList").append('<li class=""><div class="time"> '+ kuaiRecodList.ftime + '</div><div class="dot"></div><div class="text"> '+ kuaiRecodList.context +'</div></li>');
                              }
                          }
                      }
                  }
              });
          }
          
          // 驗證姓名和地址是否為空
          function verifyNameAndAddress(name, address) {
              if (name !='' && address !='') {
                  return true;
              }
              return false;
          }
          
          function nullAlert() {
              bootbox.alert({
                  title: titleTip,
                  message: '所有項均為必填!'
              });
          }
          
          // 點擊查詢按鈕
          $('#queryBtn').click(function () {
              var age=$('#queryAgeText').val();
              // 刷新并跳轉到第一頁
              $testTable.bootstrapTable('selectPage', 1);
          
          });
          
          // 點擊重置按鈕,清空查詢條件并跳轉回第一頁
          $('#resetBtn').click(function() {
              $('.form-group :text').val('');
              $testTable.bootstrapTable('selectPage', 1);
          });
          
          // 用于修改服務器資源
          function exchangeData(path, id, userName, phone, kuaiDiNo, company) {
              $.ajax({
                  url: path,
                  type: 'post',
                  data : {
                      id: id,
                      userName: userName,
                      phone: phone,
                      kuaiDiNo: kuaiDiNo,
                      company: company
                  },
                  success: function(res) {
                      bootbox.alert({
                          title: titleTip,
                          message: res.message
                      });
                      // 在每次提交操作后返回首頁
                      $testTable.bootstrapTable('selectPage', 1);
                  }
              });
          }
          
          // 新增
          $('#addBtn').click(function() {
              $('#addNameText').val('');
              $('#addPhoneText').val('');
              $('#addKuaiDiNoText').val('');
          	   $('#addCompanyText').val('');
              $('#addModal').modal('show');
          });
          
          $('#saveAdd').click(function() {
              $('#addModal').modal('hide');
              bootbox.confirm({
                  title: titleTip,
                  message: '確認增加?',
                  callback: function (flag) {
                      if (flag) {
                          var userName=$('#addNameText').val();
                          var phone=$('#addPhoneText').val();
                          var kuaiDiNo=$('#addKuaiDiNoText').val();
                          var company=$('#addCompanyText').val();
                          if (verifyNameAndAddress(userName, kuaiDiNo)) {
                              exchangeData('addKuaiDi', null, userName, phone, kuaiDiNo, company);
                          } else {
                              nullAlert();
                          }
                      }
                  }
              });
          });
          
          var mid;
          
          // 修改
          function modifyKuaiDi(id, name, age, address) {
              mid=id;
              $('#modifyNameText').val(name);
              $('#modifyPhoneText').val(age);
              $('#modifyKuaiDiNoText').val(address);
          	$('#modifyCompanyText').val(address);
              $('#modifyModal').modal('show');
          }
          
          $('#saveModify').click(function() {
              $('#modifyModal').modal('hide');
              bootbox.confirm({
                  title: titleTip,
                  message: '確認修改?',
                  callback: function (flag) {
                      if (flag) {
                          var userName=$('#modifyNameText').val();
                          var phone=$('#modifyPhoneText').val();
                          var kuaiDiNo=$('#modifyKuaiDiNoText').val();
                          var company=$('#modifyCompanyText').val();
                          if (verifyNameAndAddress(userName, phone)) {
                              exchangeData('modifyKuaiDi', mid, userName, phone, kuaiDiNo, company);
                          } else {
                              nullAlert();
                          }
                      }
                  }
              });
          });
          
          // 刪除
          function delKuaiDi(id) {
              bootbox.confirm({
                  title: titleTip,
                  message: '確認刪除?',
                  callback: function(flag) {
                      if (flag) {
                          exchangeData("delKuaiDi", id);
                      }
                  }
              });
          

          2.4運行項目

          修改配置文件 項目配置文件src/resources/application.properties,根據實際情況修改對應的數據庫連接信息。

          #MySQL配置
          spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
          spring.datasource.url=jdbc:mysql://localhost:3306/kuaidi?useUnicode=true&characterEncoding=UTF-8
          spring.datasource.username=root #數據庫賬號
          spring.datasource.password=root #數據庫密碼
          #MyBatis日志配置
          mybatis.mapperLocations=classpath:mapper/*.xml
          mybatis.config-location=classpath:/config/mybatis-config.xml
          #端口配置
          server.port=8082
          
          # 定位模板的目錄
          spring.mvc.view.prefix=classpath:/templates/
          # 給返回的頁面添加后綴名
          spring.mvc.view.suffix=.html

          創建數據庫表 表結構如下:

          DROP TABLE IF EXISTS `kuaidi`;
          CREATE TABLE `kuaidi`  (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收件人姓名',
            `phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收件人電話',
            `kuaidi_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '快遞單號',
            `company` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '快遞公司名稱拼音',
            `create_time` datetime(0) NULL DEFAULT NULL,
            PRIMARY KEY (`id`) USING BTREE
          ) ENGINE=InnoDB AUTO_INCREMENT=10 CHARACTER SET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=Dynamic;

          運行 將項目導入Idea工具,找到com.wangzg.kuaidi.KuaiDiApplication文件,執行main方法即可,如下圖:

          三、部署

          3.1 jar部署

          上傳安裝包 在服務器創建/usr/myworkspace,執行下面命令可直接創建:

          mkdir -p /usr/myworkspace
          復制代碼

          下載相關文件,上傳到服務器/usr/myworkspace。下載地址:github.com/hellowHuaai… 文件主要包括:

          • application.properties 說明:項目配置文件,可能會涉及到修改服務器端口,數據庫訪問、端口、賬號、密碼等。
          • kuaidi.jar 說明:后端服務的可執行jar文件。
          • kuaidi.sql 說明:數據庫初始化腳本。
          • start.sh 說明: 啟動服務器shell腳本。
          • stop.sh 說明: 停止服務器shell腳本。

          初始化數據庫 打開Navicat工具,選中數據庫,右鍵選擇運行SQL文件...,具體操作,這樣數據庫就初始化完成。

          運行項目
          在服務器/usr/myworkspace目錄下,執行如下命令,即可運行項目:

          chmod +x *.sh #給所有 .sh文件添加執行權限
          ./start.sh

          3.2 Docker部署

          Docker 容器化部署項目,需要創建一個 mysql 的容器,創建kuaidi的容器,再初始化一下數據庫。

          創建數據庫容器 代碼如下:

          docker run -d --name mysql5.7 -e MYSQL_ROOT_PASSWORD=root -it -p 3306:3306 daocloud.io/library/mysql:5.7.7-rc

          導入數據庫腳本 數據庫腳本kuaidi.sql內容如下:

          create DATABASE kuaidi;
          use kuaidi;
          
          SET NAMES utf8mb4;
          SET FOREIGN_KEY_CHECKS=0;
          
          DROP TABLE IF EXISTS `kuaidi`;
          CREATE TABLE `kuaidi`  (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收件人姓名',
            `phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收件人電話',
            `kuaidi_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '快遞單號',
            `company` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '快遞公司名稱拼音',
            `create_time` datetime(0) NULL DEFAULT NULL,
            PRIMARY KEY (`id`) USING BTREE
          ) ENGINE=InnoDB AUTO_INCREMENT=10 CHARACTER SET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=Dynamic;

          然后執行下面命令,就可以導入kuaidi.sql腳本:

          docker exec -i mysql5.7 mysql -uroot -proot mysql < kuaidi.sql

          創建kuaidi容器 執行下面命令就可以創建容器:

          docker run -d -p 9082:8082 -v application.properties:/home/conf/application.properties --name kuaidi1 huaairen/kuaidi:latest

          注:application.properties文件為項目的配置文件,在src/main/resources目錄下;huaairen/kuaidi:latest是我打包好的鏡像,直接下載就可以。

          四、最后

          項目功能還特別簡陋,很多功能需要開發和完善。如果你也遇到類似的問題我們可以一起討論,合作共贏哦!

          作者:不安分的猿人

          鏈接:https://juejin.im/post/5e9313ece51d4546c62f9ac4

          來源:掘金

          戶信息:

          https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html


          獲取用戶信息wx.getUserProfile(Object object)

          獲取用戶信息。頁面產生點擊事件(例如 buttonbindtap 的回調中)后才可調用,每次請求都會彈出授權窗口,用戶同意后返回 userInfo。該接口用于替換 wx.getUserInfo。

          Bug & Tip

          1. tip:僅小程序中 wx.getUserInfo 接口進行調整,小游戲中不受影響;
          2. tip:開發者工具中僅 2.10.4 及以上版本可訪問 wx.getUserProfile 接口,在真機上可參考示例代碼進行判斷,無需根據版本號或者 canIUse 進行條件。
          3. tipwx.getUserProfile 返回的加密數據中不包含 openIdunionId 字段。
          4. bug:開發者工具中 2.10.4~2.16.1 基礎庫版本通過 <button open-type="getUserInfo"> 會返回真實數據,真機上此區間會按照公告返回匿名數據。
          <block wx:if="{{!hasUserInfo}}">
            <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 
              獲取頭像昵稱 (彈窗)</button>
            <button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 
              獲取頭像昵稱(不彈窗了) </button>
          </block>
          Page({
            data: {
              userInfo: {},
              hasUserInfo: false,
              canIUseGetUserProfile: false,
            },
            onLoad() {
              if (wx.getUserProfile) {
                this.setData({
                  canIUseGetUserProfile: true
                })
              }
            },
            getUserProfile(e) {//獲取用戶信息彈窗
              // 推薦使用wx.getUserProfile獲取用戶信息,開發者每次通過該接口獲取用戶個人信息均需用戶確認
              // 開發者妥善保管用戶快速填寫的頭像昵稱,避免重復彈窗
              wx.getUserProfile({
                desc: '用于完善會員資料', // 聲明獲取用戶個人信息后的用途,后續會展示在彈窗中,請謹慎填寫
                success: (res)=> {
                  this.setData({
                    userInfo: res.userInfo,
                    hasUserInfo: true
                  })
                }
              })
            },
            getUserInfo(e) { //小程序進行了調整,不再彈窗確認
              // 不推薦使用getUserInfo獲取用戶信息,預計自2021年4月13日起,getUserInfo將不再彈出彈窗,并直接返回匿名的用戶個人信息
              this.setData({
                userInfo: e.detail.userInfo,
                hasUserInfo: true
              })
            },
          })

          獲取用戶手機號

          <button open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber" 
          class="mybtn" >點擊登錄</button>
          onGetPhoneNumber(e){
            console.log(e);
            if (e.detail.errMsg=="getPhoneNumber:ok") { //允許授權 
              uni.request({
                url: getApp().globalData.url+"/savePhone",
                method: 'POST',
                data: {
                  "encrypted_data":e.detail.encryptedData,
                  "iv":e.detail.iv,
                  "openid":this.openid
                },
                success: (res)=> {
                  this.token=res.data.data.token
                  // .....
                }
              });
          
            } 
          }

          說明:getUserProfile和getPhoneNumber,都需要用戶點擊操作。

          自:Python知識圈

          各類無次數限制的免費API接口整理,主要是聚合數據上和API Store上的一些,還有一些其他的。

          聚合數據提供30大類,160種以上基礎數據API服務,國內最大的基礎數據API服務,下面就羅列一些免費的各類API接口。

          早知道這些API,我就不到處爬爬爬了...

          手機號碼歸屬地API接口:

          https://www.juhe.cn/docs/api/id/11

          歷史上的今天API接口:

          https://www.juhe.cn/docs/api/id/63

          股票數據API接口:

          https://www.juhe.cn/docs/api/id/21

          全國WIFI接口:

          https://www.juhe.cn/docs/api/id/18

          星座運勢接口:

          https://www.juhe.cn/docs/api/id/58

          黃金數據接口:

          https://www.juhe.cn/docs/api/id/29

          語音識別接口:

          https://www.juhe.cn/docs/api/id/134

          周公解夢接口:

          https://www.juhe.cn/docs/api/id/64

          天氣預報API接口:

          https://www.juhe.cn/docs/api/id/73

          身份證查詢API接口:

          https://www.juhe.cn/docs/api/id/38

          笑話大全API接口:

          https://www.juhe.cn/docs/api/id/95

          郵編查詢接口:

          https://www.juhe.cn/docs/api/id/66

          老黃歷接口:

          https://www.juhe.cn/docs/api/id/65

          網站安全檢測接口:

          https://www.juhe.cn/docs/api/id/19

          手機固話來電顯示接口:

          https://www.juhe.cn/docs/api/id/72

          基金財務數據接口:

          https://www.juhe.cn/docs/api/id/28

          成語詞典接口:

          https://www.juhe.cn/docs/api/id/157

          新聞頭條接口:

          https://www.juhe.cn/docs/api/id/235

          IP地址接口:

          https://www.juhe.cn/docs/api/id/1

          問答機器人接口:

          https://www.juhe.cn/docs/api/id/112

          匯率API接口:

          https://www.juhe.cn/docs/api/id/80

          電影票房接口:

          https://www.juhe.cn/docs/api/id/44

          萬年歷API接口:

          https://www.juhe.cn/docs/api/id/177

          NBA賽事接口:

          https://www.juhe.cn/docs/api/id/92

          IP地址查詢

          http://apistore.baidu.com/apiworks/servicedetail/114.html

          頻道新聞API_易源

          http://apistore.baidu.com/apiworks/servicedetail/688.html

          微信熱門精選 :

          http://apistore.baidu.com/apiworks/servicedetail/632.html

          天氣查詢

          http://apistore.baidu.com/apiworks/servicedetail/112.html

          中國和世界天氣預報

          http://apistore.baidu.com/apiworks/servicedetail/478.html

          股票查詢

          http://apistore.baidu.com/apiworks/servicedetail/115.html

          身份證查詢:

          http://apistore.baidu.com/apiworks/servicedetail/113.html

          美女圖片

          http://apistore.baidu.com/apiworks/servicedetail/720.html

          音樂搜索

          http://apistore.baidu.com/apiworks/servicedetail/1020.html

          圖靈機器人

          http://apistore.baidu.com/apiworks/servicedetail/736.html

          匯率轉換

          http://apistore.baidu.com/apiworks/servicedetail/119.html

          節假日

          http://apistore.baidu.com/apiworks/servicedetail/1116.html

          pullword在線分詞服務

          http://apistore.baidu.com/apiworks/servicedetail/143.html

          去哪兒網火車票

          http://apistore.baidu.com/apiworks/servicedetail/697.html

          笑話大全

          http://apistore.baidu.com/apiworks/servicedetail/864.html

          銀行卡查詢服務

          http://apistore.baidu.com/apiworks/servicedetail/735.html

          語音合成

          http://apistore.baidu.com/apiworks/servicedetail/867.html

          宅言API-動漫臺詞接口

          http://apistore.baidu.com/apiworks/servicedetail/446.html

          去哪兒景點門票查詢

          http://apistore.baidu.com/apiworks/servicedetail/140.html

          手機號碼歸屬地

          http://apistore.baidu.com/apiworks/servicedetail/794.html

          體育新聞

          http://apistore.baidu.com/apiworks/servicedetail/711.html

          手機歸屬地查詢

          http://apistore.baidu.com/apiworks/servicedetail/709.html

          科技新聞

          http://apistore.baidu.com/apiworks/servicedetail/1061.html

          空氣質量指數

          http://apistore.baidu.com/apiworks/servicedetail/116.html

          天狗健康菜譜

          http://apistore.baidu.com/apiworks/servicedetail/987.html

          熱門游記列表

          http://apistore.baidu.com/apiworks/servicedetail/520.html

          天狗藥品查詢

          http://apistore.baidu.com/apiworks/servicedetail/916.html

          漢字轉拼音

          http://apistore.baidu.com/apiworks/servicedetail/1124.html

          國際新聞

          http://apistore.baidu.com/apiworks/servicedetail/823.html

          彩票

          http://apistore.baidu.com/apiworks/servicedetail/164.html

          微信精選

          http://apistore.baidu.com/apiworks/servicedetail/863.html

          天狗健康資訊

          http://apistore.baidu.com/apiworks/servicedetail/888.html

          興趣點檢索

          http://apistore.baidu.com/apiworks/servicedetail/182.html

          用藥參考

          http://apistore.baidu.com/apiworks/servicedetail/754.html

          天狗健康知識

          http://apistore.baidu.com/apiworks/servicedetail/899.html

          奇聞趣事

          http://apistore.baidu.com/apiworks/servicedetail/633.html

          花邊新聞

          http://apistore.baidu.com/apiworks/servicedetail/768.html

          天狗醫院大全

          http://apistore.baidu.com/apiworks/servicedetail/988.html

          生活健康

          http://apistore.baidu.com/apiworks/servicedetail/989.html

          一些其他的API接口

          豆瓣開放

          https://developers.douban.com/wiki/

          淘寶開放平臺

          http://open.taobao.com/

          圖靈語音

          http://www.tuling123.com/help/h_cent_andriodsdk.jhtml

          訊飛語音

          http://www.xfyun.cn/robots/solution

          馬化騰的微信開放平臺(對應的還有騰訊開放平臺)

          https://open.weixin.qq.com/

          融云IM

          https://developer.rongcloud.cn/signin

          百度開發者中心

          http://developer.baidu.com/

          人臉識別

          http://www.faceplusplus.com.cn/

          高德地圖:

          http://lbs.amap.com/

          蜻蜓FM:

          http://open.qingting.fm


          主站蜘蛛池模板: 免费日本一区二区| 中文字幕一区二区三区精华液 | 国产乱码精品一区二区三区| 国产精品乱码一区二区三| 日韩视频一区二区三区| 日韩熟女精品一区二区三区| 精品国产亚洲一区二区三区在线观看| 三上悠亚精品一区二区久久| 日韩动漫av在线播放一区| 无码一区二区三区爆白浆| 末成年女AV片一区二区| 日本视频一区在线观看免费| 99精品国产高清一区二区麻豆| 亚洲色精品VR一区区三区| 一区二区三区美女视频| 久久精品国产免费一区| 久久一区二区免费播放| 精品久久国产一区二区三区香蕉| 国产麻豆剧果冻传媒一区 | 无码国产精品一区二区免费式芒果| 亚洲av无码天堂一区二区三区| 国产成人综合一区精品| 精品无码人妻一区二区免费蜜桃| 亚洲午夜精品一区二区公牛电影院 | 无码一区二区三区爆白浆| 无码国产精品一区二区免费模式| 亚洲AV本道一区二区三区四区 | 国产内射999视频一区| 国产一区二区精品| 亚洲午夜精品一区二区麻豆| 一本大道在线无码一区| 99精品久久精品一区二区| 成人日韩熟女高清视频一区| 中文精品一区二区三区四区| 国产SUV精品一区二区88L| 国偷自产av一区二区三区| 亚洲欧美成人一区二区三区| 一区二区在线免费视频| 无码精品国产一区二区三区免费| 69福利视频一区二区| 一区二区三区四区在线视频|