时间:2022-10-23 11:17:37 | 栏目:Golang | 点击:次
前言:
vcf文件:?VCF是通讯录格式文件,一般需要用手机通讯录导入导出的文件格式都是vcf格式。?
目的:?如果你是卖房销售,或者你是做什么推销的,你可以生成同城的手机号,一个个打电话推销。?
package number /* @Time : 2021/12/22 17:44 @Author :dengfeng_hu @File : phone @Software: GoLand */ import ( "bufio" "fmt" "io" "os" "strconv" "strings" "time" ) const ( inputFilePath = "D:/phone.txt" fileName = "洛阳" last = "36" fileSize = 5 outputPath = "D://phoneNumber" ) func getNum(fileName string) int { var num = 1 for { if _,err:=os.Stat("D://phoneNumber/" + fileName + strconv.Itoa(num)+".vcf"); os.IsNotExist(err){ return num } num++ } } func Exe() { mid := read() for i:=0;i<len(mid);i=i+5{ var subList []string if i+fileSize<len(mid){ subList = mid[i:i+fileSize:len(mid)] }else{ subList = mid[i:len(mid):len(mid)] } fmt.Println(subList) MyTest(subList,fileName,last) } } func MyTest(mid []string,fileName string,last string){ num := getNum(fileName) file, err := os.OpenFile(outputPath+"/" + fileName +strconv.Itoa(num) +".vcf", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { fmt.Println("文件打开失败", err) return } //及时关闭file句柄 defer file.Close() write := bufio.NewWriter(file) count:=1 for i := 0;i<len(mid);i++{ for j := 0;j<100;j++{ phoneNumber := strings.ReplaceAll(mid[i],"\r\n","") + fmt.Sprintf("%02d", j) + last makeNumber(phoneNumber,write,strconv.Itoa(count)) count++ } } makeNumber("15804299051",write,strconv.Itoa(count)) write.Flush() fmt.Println("文件创建成功,时间:"+time.Now().Format("2006-01-02 15:04:05")) } func makeNumber(num string,w *bufio.Writer,index string){ w.WriteString("BEGIN:VCARD" + "\r\n") w.WriteString("VERSION:3.0" + "\r\n") w.WriteString("FN;CHARSET=UTF-8:1" + "\r\n") w.WriteString("N;CHARSET=UTF-8:;;" + "A"+index +";;" + "\r\n") w.WriteString("TEL;TYPE=CELL:" + num + "\r\n") w.WriteString("END:VCARD" + "\r\n") } func read() []string{ var mid []string f, err := os.Open(inputFilePath) if err != nil { panic(err) } defer f.Close() rd := bufio.NewReader(f) for { line, err := rd.ReadString('\n') //以'\n'为结束符读入一行 if err != nil || io.EOF == err { break } mid = append(mid,line) } fmt.Println("mid size:" + strconv.Itoa(len(mid))) fmt.Println("mid " ) fmt.Println(mid) return mid }
inoputFilePath
是输入文件,也就是你想生成哪个城市的电话号的前六位。last是后两位。
outputPath
是生成文件目录
比如188**23,后两位就是23,fileSize是文件号码数量。5代表一个文件500个电话号
文件来源直接百度搜。比如洛阳188查号吧
查好了复制进去即可。