1

Achievement display

批量生成快递地址

URL for batch generation of express addresses: http://poi.moyutime.cn/

Our company often needs to generate a courier address. I extracted this function separately and made it into a website (free for inquiry, fee for download, don’t mind if you click ).

In this way, we need to generate the express address in the future, just download it, and no longer need to run the command line.

There are also friends who need the same, you can take a look. The little friends who are not bad, you can find me, the price is favorable, and the delivery is in seconds. Like me, the cyst is shy, so I continued to look down, and I said my thoughts. See if it helps you.

premise

In some companies, especially e-commerce companies like us, it is often necessary to generate fake courier addresses for system testing.

A few days ago, our group developed a delivery system, which requires a fake courier address.

And not one, but several thousand, and it is also required to be accurate to the cell.

When I first heard this request, I was stunned.

However, as an 8-year-old R&D dog, I thought of a solution in a blink of an eye.

After tossing for a day, finally a perfect cross.

ideas

In fact, the idea is very simple. To generate a courier address, we must first know the addresses of communities across the country. With the community address, we randomly generate the account number, name and mobile phone number to form a courier address.

The community address is also easy to obtain. AutoNavi Map, Tencent Map and Baidu Map all provide corresponding interfaces. Here I take the Gaode map as an example, and tell me my method.

develop

1. Get the addresses of all communities in the country

First, register an account on the AutoNavi map open platform and create an application.

Create an app

高德地图创建应用

add key
I am developing on the web side, so here I choose [Web side (JS API)], you can choose different types according to your needs.

添加key

After adding it, we got a key generated by Gaode Map for us. With this key, we can call the api provided by Gaode Map. Because we chose the web service. So our api document is [Web Service API]

View documentation

查看文档

To search for a community, the api we need to call is [Search POI]

搜索poi

View interface

The interface we want to call is this:

接口参数

//restapi.amap.com/v3/place/text?key=your key&keywords=cell&types=120000&city=110101&children=1&offset=20&page=1&extensions=base&citylimit=true

The parameters are as follows

  • key: The key just generated.
  • keywords: The keyword of the search, we are searching for the community, so fill in the community
  • types: poi type, the poi type of the cell is 120000. If you want to view other types, you can click the POI classification code
  • city: You can fill in the city name or citycode or adcode here. For more accurate results, we choose to fill in adcode. 110101 is the adcode of Dongcheng District, Beijing. For the adcodes of other places, please check the city code table below
  • offset: The number of records per page, the default is 20, the maximum is 25. I used the default value of 20
  • page: the current page number, the default is 1
  • citylimit: return only the specified city data

request result

请求结果

In the returned result, count is the total number, and the pois array is the detailed information of each cell. Because our offset is set to 20, only 20 cell data can be returned in one request. We first store these data in our database, so that we can call them later.

If you want to traverse all the cells, you need to use a loop to request the interface multiple times by changing the page parameter.

This is quite simple, so I won't go into it.

After getting all the cell data in the area. We can get the data of all districts in the country by traversing all the regions in the city code table .

One account of Gaode Map can request 5,000 times for free a day. I borrowed a lot of accounts, and I finally got it. The database I use is mongodb, and the structure stored in the database is as follows, there are about 380,000 pieces of data in total.

数据库数据结构

Generate random building number, unit number and household number

A completed express address usually also needs to include the user's building number, unit number and household number. We can use Math.random() to generate it randomly.
In order to make the data look less outrageous, we randomly generate the floor between 1-16th floor, and the unit is randomly generated between 1-4.

code show as below:

 // 生成随机单元号
function randomUnitNum() {
  // 楼号 1-16 随机生成
  // 单元 1-4 之间随机生成
  // 户号 [1-6]0[1-6]
  return randomNum(1, 16) + '楼' + randomNum(1, 4) + '单元' + randomNum(1, 6) + '0' + randomNum(1, 6) + '号';
}

Generate random phone number

code show as below:

 /**
 * 生成随机手机号
 * @return
 */
function randomPhoneNum() {
  const preNumList = [131, 135, 137, 139, 151, 150, 189, 136, 186, 187, 152, 138, 180];
  const rNum = randomNum(0, 12);
  const afNum = randomNum(13221010, 98241249);
  return String(preNumList[rNum]) + String(afNum);
}

Generate random names

code show as below:

 /**
 * 随机生成用户姓名
 * @return 返回随机生成的用户姓名
 */
function randomUserName() {
  const xStr = '陈林黃张李王吴刘蔡杨许郑谢洪郭邱曾廖赖徐周叶苏庄吕江何萧罗高周叶苏庄吕江何萧罗高潘简朱锺彭游詹胡施沈余卢梁赵颜柯翁魏孙戴范方宋邓杜傅侯曹薛丁卓马阮董唐温蓝蒋石古纪姚连冯欧程汤黄田康姜汪白邹尤巫钟黎涂龚严韩袁金童陆夏柳凃邵';
  const femaleStr = '嘉琼桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊勤珍贞莉兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳';
  const maleStr = '涛昌进林有坚和彪博诚先敬震振壮会群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发成康星光天达安岩中茂武新利清飞彬富顺信子杰楠榕风航弘';
  const allNameStr = femaleStr + maleStr;
  const ran = randomNum(0, 10);
  let mingStr = '';
  if (ran < 1) {
    // 姓名为2个字
    mingStr = allNameStr[randomNum(0, allNameStr.length)];
  } else {
    mingStr = allNameStr[randomNum(0, allNameStr.length)] + allNameStr[randomNum(0, allNameStr.length)];
  }
  return xStr[randomNum(0, xStr.length - 1)] + mingStr;
}

Generate courier address

Through the above steps, we get all the data we want. Through this data, we want to generate a courier address, which is not too easy. So far, this requirement has been developed.

A complete data structure is as follows:

完整地址


郭邯
496 声望17 粉丝

长期招聘女朋友


« 上一篇
git的分支管理