842 lines
32 KiB
Plaintext
842 lines
32 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e6dcc663-e0ed-4ea3-b442-11f229f4af94",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 新增体测单位"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "360f0a97-d73d-43f3-9f7a-0f9582103c82",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-04T01:13:15.511726Z",
|
|
"iopub.status.busy": "2025-03-04T01:13:15.510982Z",
|
|
"iopub.status.idle": "2025-03-04T01:13:15.594359Z",
|
|
"shell.execute_reply": "2025-03-04T01:13:15.593901Z",
|
|
"shell.execute_reply.started": "2025-03-04T01:13:15.511654Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"place\"]\n",
|
|
"\n",
|
|
"place_id = 250226\n",
|
|
"place_code = \"16\"\n",
|
|
"dw_name = \"山东东营陈庄镇\"\n",
|
|
"dw_jc = \"山东东营陈庄镇\"\n",
|
|
"myquery = { \"id\": place_id }\n",
|
|
"num = mycol.count_documents(myquery)\n",
|
|
"if num>0:\n",
|
|
" print(num)\n",
|
|
"else:\n",
|
|
" mydict = { \"id\":place_id,\"name\": dw_name, \"code\": place_code }\n",
|
|
" x = mycol.insert_one(mydict) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "dcfbd41f-ca70-4f15-9153-60e6aaac27e8",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成手机验证码"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "6ce2cbc7-435a-461c-bdb8-abd9a6962fbc",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-04T01:47:46.378353Z",
|
|
"iopub.status.busy": "2025-03-04T01:47:46.377604Z",
|
|
"iopub.status.idle": "2025-03-04T01:47:46.556327Z",
|
|
"shell.execute_reply": "2025-03-04T01:47:46.555855Z",
|
|
"shell.execute_reply.started": "2025-03-04T01:47:46.378281Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"116 ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import math\n",
|
|
"import glob\n",
|
|
"import random\n",
|
|
"from pathlib import Path\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"\n",
|
|
"place_id = 250226\n",
|
|
"place_code = \"16\"\n",
|
|
"dw_name = \"山东东营陈庄镇\"\n",
|
|
"dw_jc = \"山东东营陈庄镇\"\n",
|
|
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n",
|
|
"fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n",
|
|
"\n",
|
|
"code_list = []\n",
|
|
"for i in range(10): # 0~9\n",
|
|
" code_list.append(str(i))\n",
|
|
"list1 = []\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"query1 = { \"place_id\": place_id }\n",
|
|
"list2 = []\n",
|
|
"mydoc = mycol.find(query1,{ \"code\": 1, \"_id\": 0 })\n",
|
|
"\n",
|
|
"for x in mydoc:\n",
|
|
" list2.append(x['code'])\n",
|
|
"\n",
|
|
"i = 0\n",
|
|
"while i < len(fls):\n",
|
|
" code = random.sample(code_list,4) #随机取3位数\n",
|
|
" code_num = ''.join(code) \n",
|
|
" if place_code+code_num not in list1 and place_code+code_num not in list2:\n",
|
|
" list1.append(place_code+code_num)\n",
|
|
" i +=1\n",
|
|
"i = 0\n",
|
|
"list2= []\n",
|
|
"for fn in fls:\n",
|
|
" dict2 = {}\n",
|
|
" fi_name =Path(fn).stem.split('-')[0]\n",
|
|
" #fi_name =Path(fn).stem\n",
|
|
" code = int(fi_name)\n",
|
|
" dxm = list1[i]\n",
|
|
" dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}\n",
|
|
" list2.append(dict2)\n",
|
|
" i +=1\n",
|
|
"x = mycol.insert_many(list2)\n",
|
|
"print(len(list2),'ok') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ad9e943a-bb3a-4d58-93ef-cc442a80effa",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 批量发送短信(测试)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "5f665c0f-8d30-4759-b7f8-fb7e13b98efa",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-04T01:54:43.144665Z",
|
|
"iopub.status.busy": "2025-03-04T01:54:43.143709Z",
|
|
"iopub.status.idle": "2025-03-04T01:54:43.267863Z",
|
|
"shell.execute_reply": "2025-03-04T01:54:43.267357Z",
|
|
"shell.execute_reply.started": "2025-03-04T01:54:43.144573Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1 17354672396 0108-徐中华.pdf 160486\n",
|
|
"2 13563358955 0103-薄友梅.pdf 163176\n",
|
|
"3 13561096259 0095-王天成.pdf 162197\n",
|
|
"4 13371558516 0047-刘芳.pdf 160524\n",
|
|
"5 14768999777 0112-杨国良.pdf 168926\n",
|
|
"6 17754600886 0094-崔明波.pdf 167621\n",
|
|
"7 18562083357 0053-梁文硕.pdf 162163\n",
|
|
"8 15550539133 0097-李燕.pdf 166914\n",
|
|
"9 18254652100 0074-王鲁笑.pdf 160615\n",
|
|
"10 13625462769 0005-李卫忠.pdf 167935\n",
|
|
"11 15266065108 0044-纪荣平.pdf 166395\n",
|
|
"12 17754684486 0063-孙霞.pdf 165102\n",
|
|
"13 15318307578 0018-冯海华.pdf 163802\n",
|
|
"14 13561011787 0033-石振波.pdf 168039\n",
|
|
"15 13561006241 0041-薛真.pdf 167614\n",
|
|
"16 15965466216 0111-李培荣.pdf 167615\n",
|
|
"17 18562961538 0093-李乐.pdf 168561\n",
|
|
"18 13465269869 0015-王翠霞.pdf 163169\n",
|
|
"19 17754629112 0054-孟玲.pdf 162869\n",
|
|
"20 18554626567 0122-刘建云.pdf 161832\n",
|
|
"21 15318391717 0080-李小青.pdf 166590\n",
|
|
"22 17754629138 0067-牟艳红.pdf 166379\n",
|
|
"23 17754629077 0062-胡振云.pdf 162831\n",
|
|
"24 17754651259 0124-王学晴.pdf 169650\n",
|
|
"25 15254633988 0009-张伟花.pdf 164287\n",
|
|
"26 18562007818 0083-蔻艳.pdf 167918\n",
|
|
"27 18654691866 0001-陈彤彤.pdf 166271\n",
|
|
"28 18954628871 0100-张玉荣.pdf 167910\n",
|
|
"29 19854689029 0082-陈希珍.pdf 164523\n",
|
|
"30 15154681871 0010-王兰玉.pdf 167460\n",
|
|
"31 13780756776 0023-张仕荣.pdf 164763\n",
|
|
"32 15154622086 0077-孙义芬.pdf 164789\n",
|
|
"33 13455721686 0036-陈光梅.pdf 162051\n",
|
|
"34 13475465246 0064-李铭悦.pdf 164913\n",
|
|
"35 13181857658 0116-韩书贞.pdf 165482\n",
|
|
"36 13562298356 0084-胡冰叶.pdf 165170\n",
|
|
"37 18562961552 0101-王乃玲.pdf 161429\n",
|
|
"38 13371528169 0042-刘志芳.pdf 167682\n",
|
|
"39 17754629165 0048-徐雪花.pdf 165471\n",
|
|
"40 13256477708 0117-崔树红.pdf 161758\n",
|
|
"41 13356619896 0114-陈延红.pdf 167963\n",
|
|
"42 13287371168 0038-王守美.pdf 166920\n",
|
|
"43 15715468750 0006-韩小荣.pdf 168734\n",
|
|
"44 15154619169 0079-刘桂.pdf 164271\n",
|
|
"45 17754629082 0070-王芳.pdf 168370\n",
|
|
"46 15306476627 0055-张韶岩.pdf 166984\n",
|
|
"47 13705467605 0126-巴月华.pdf 160364\n",
|
|
"48 17754629057 0065-商孟加.pdf 161934\n",
|
|
"49 19963763561 0123-陈建正.pdf 160236\n",
|
|
"50 13325059838 0025-崔志猛.pdf 162853\n",
|
|
"51 15318328975 0040-王元.pdf 163259\n",
|
|
"52 13205471255 0029-张秀奎.pdf 165897\n",
|
|
"53 13361503856 0102-宋珊珊.pdf 167024\n",
|
|
"54 18954680512 0059-孟祥菊.pdf 162648\n",
|
|
"55 13465275185 0060-张春先.pdf 169518\n",
|
|
"56 13361522787 0069-王明杰.pdf 165038\n",
|
|
"57 13054610918 0057-郭立凯.pdf 168106\n",
|
|
"58 18506466571 0091-赵培芬.pdf 166937\n",
|
|
"59 13181854171 0107-董强.pdf 168902\n",
|
|
"60 13210388535 0071-刘俊志.pdf 161024\n",
|
|
"61 13306475903 0072-王芹.pdf 163160\n",
|
|
"62 15965465758 0043-郭振芹.pdf 165241\n",
|
|
"63 13355460615 0035-李跃粉.pdf 165670\n",
|
|
"64 18266665051 0052-王一涵.pdf 162679\n",
|
|
"65 13054600511 0125-季书奎.pdf 164526\n",
|
|
"66 15314325556 0045-张绪民.pdf 163645\n",
|
|
"67 13963355696 0118-王兴业.pdf 163275\n",
|
|
"68 13081417578 0028-李召兰.pdf 168653\n",
|
|
"69 15965466030 0086-陈春华.pdf 165723\n",
|
|
"70 15254639986 0014-陈召云.pdf 164920\n",
|
|
"71 13792069959 0016-崔士叶.pdf 163204\n",
|
|
"72 13905465022 0075-孙丽.pdf 165792\n",
|
|
"73 17754629228 0088-陈奎霞.pdf 164810\n",
|
|
"74 15154623768 0017-崔业常.pdf 166814\n",
|
|
"75 15965466216 0032-李培荣.pdf 164150\n",
|
|
"76 13864785309 0115-杨建军.pdf 162097\n",
|
|
"77 15990986892 0104-林燕燕.pdf 169407\n",
|
|
"78 18764586870 0056-曹志捷.pdf 168719\n",
|
|
"79 15315038808 0119-韩永强.pdf 165184\n",
|
|
"80 18562961530 0106-张玉军.pdf 169036\n",
|
|
"81 13054673678 0039-王新娥.pdf 167120\n",
|
|
"82 13706470006 0024-毕玉江.pdf 165769\n",
|
|
"83 13954696798 0008-陈振玉.pdf 163164\n",
|
|
"84 18766719018 0092-程艳娟.pdf 162109\n",
|
|
"85 17754629160 0090-徐妮.pdf 162709\n",
|
|
"86 15954759855 0019-陈新英.pdf 162859\n",
|
|
"87 13375461776 0022-盖新茂.pdf 164270\n",
|
|
"88 15954671399 0121-韩秀娥.pdf 168275\n",
|
|
"89 18954680397 0046-尚玉兰.pdf 161083\n",
|
|
"90 13561016489 0020-王乐花.pdf 164631\n",
|
|
"91 18860673506 0012-崔桂灵.pdf 163906\n",
|
|
"92 15665876948 0051-薄尊敏.pdf 165219\n",
|
|
"93 17754629197 0096-吴松.pdf 167890\n",
|
|
"94 18865467781 0098-徐雪梅.pdf 167148\n",
|
|
"95 17754629133 0068-李艳红.pdf 161483\n",
|
|
"96 17754600676 0066-吴根林.pdf 166370\n",
|
|
"97 13561086165 0004-李伟军.pdf 164165\n",
|
|
"98 15605469730 0089-曹莹莹.pdf 164137\n",
|
|
"99 17754629176 0050-徐凤霞.pdf 161527\n",
|
|
"100 13220505818 0026-霍卫华.pdf 160537\n",
|
|
"101 15154655057 0085-左连亮.pdf 168761\n",
|
|
"102 15275640625 0120-石东初.pdf 164391\n",
|
|
"103 13562257108 0081-李英霞.pdf 165483\n",
|
|
"104 15318382108 0087-刘肖丽.pdf 160973\n",
|
|
"105 13625462769 0109-李卫忠.pdf 167350\n",
|
|
"106 17754600760 0061-胡菲菲.pdf 169176\n",
|
|
"107 13006548466 0037-李振琴.pdf 162870\n",
|
|
"108 18954676358 0058-赵凯.pdf 167032\n",
|
|
"109 15552779321 0105-刘胜彩.pdf 163867\n",
|
|
"110 13563395385 0027-王振泉.pdf 164018\n",
|
|
"111 19854689027 0078-张卫卫.pdf 164520\n",
|
|
"112 17754629226 0049-蔡立庆.pdf 169251\n",
|
|
"113 13406089611 0076-王宪芳.pdf 168925\n",
|
|
"114 17754665865 0073-韩霞.pdf 161576\n",
|
|
"115 13963351053 0099-韩英.pdf 160826\n",
|
|
"116 17754629175 0034-段德引.pdf 162306\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"import time\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"dw_jc = \"山东东营陈庄镇测试者\"\n",
|
|
"filename = 'data/陈庄检测人员.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"#place_id = 571315\n",
|
|
"myquery = { \"place_id\": place_id}\n",
|
|
"for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n",
|
|
" code = int(x['fn'].split('-')[0])\n",
|
|
" if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():\n",
|
|
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code'],'name':x['fn']}\n",
|
|
" else:\n",
|
|
" print(code,'no phone')\n",
|
|
"#print(dict2)\n",
|
|
"i=1\n",
|
|
"#dict2 = {375: {'phone': '13793180751', 'code': '0379208'}}\n",
|
|
"for k, v in dict2.items():\n",
|
|
" phone = '+86'+v['phone']\n",
|
|
" yzm = v['code']\n",
|
|
" try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 60 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.SendSmsRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" req.SignName = \"坤铭教育\"\n",
|
|
" req.TemplateId = \"1875765\" \n",
|
|
" req.TemplateParamSet = [dw_jc,yzm]\n",
|
|
" req.PhoneNumberSet = [phone]\n",
|
|
" req.SessionContext = \"\"\n",
|
|
" req.ExtendCode = \"\"\n",
|
|
" req.SenderId = \"\"\n",
|
|
" #resp = client.SendSms(req)\n",
|
|
" #dict3 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
" #print(v['phone'],dict3['SendStatusSet'][0][\"Message\"])\n",
|
|
" print(i,v['phone'],v['name'], v['code'])\n",
|
|
" i+=1\n",
|
|
" except TencentCloudSDKException as err:\n",
|
|
" print(v['phone'],err)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b9a157f4-4772-413e-82f4-ecb7d2af8529",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 批量发送短信"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "4b2b5d76-665f-4dfe-bbd3-5c80abd8c3e3",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-04T01:57:31.101633Z",
|
|
"iopub.status.busy": "2025-03-04T01:57:31.100873Z",
|
|
"iopub.status.idle": "2025-03-04T02:07:35.250788Z",
|
|
"shell.execute_reply": "2025-03-04T02:07:35.248854Z",
|
|
"shell.execute_reply.started": "2025-03-04T01:57:31.101547Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"17354672396 160486 send success\n",
|
|
"13563358955 163176 send success\n",
|
|
"13561096259 162197 send success\n",
|
|
"13371558516 160524 send success\n",
|
|
"14768999777 168926 send success\n",
|
|
"17754600886 167621 send success\n",
|
|
"18562083357 162163 send success\n",
|
|
"15550539133 166914 send success\n",
|
|
"18254652100 160615 send success\n",
|
|
"13625462769 167935 send success\n",
|
|
"15266065108 166395 send success\n",
|
|
"17754684486 165102 send success\n",
|
|
"15318307578 163802 send success\n",
|
|
"13561011787 168039 send success\n",
|
|
"13561006241 167614 send success\n",
|
|
"15965466216 167615 send success\n",
|
|
"18562961538 168561 send success\n",
|
|
"13465269869 163169 send success\n",
|
|
"17754629112 162869 send success\n",
|
|
"18554626567 161832 send success\n",
|
|
"15318391717 166590 send success\n",
|
|
"17754629138 166379 send success\n",
|
|
"17754629077 162831 send success\n",
|
|
"17754651259 169650 send success\n",
|
|
"15254633988 164287 send success\n",
|
|
"18562007818 167918 send success\n",
|
|
"18654691866 166271 send success\n",
|
|
"18954628871 167910 send success\n",
|
|
"19854689029 164523 send success\n",
|
|
"15154681871 167460 send success\n",
|
|
"13780756776 164763 send success\n",
|
|
"15154622086 164789 send success\n",
|
|
"13455721686 162051 send success\n",
|
|
"13475465246 164913 send success\n",
|
|
"13181857658 165482 send success\n",
|
|
"13562298356 165170 send success\n",
|
|
"18562961552 161429 send success\n",
|
|
"13371528169 167682 send success\n",
|
|
"17754629165 165471 send success\n",
|
|
"13256477708 161758 send success\n",
|
|
"13356619896 167963 send success\n",
|
|
"13287371168 166920 send success\n",
|
|
"15715468750 168734 send success\n",
|
|
"15154619169 164271 send success\n",
|
|
"17754629082 168370 send success\n",
|
|
"15306476627 166984 send success\n",
|
|
"13705467605 160364 send success\n",
|
|
"17754629057 161934 send success\n",
|
|
"19963763561 160236 send success\n",
|
|
"13325059838 162853 send success\n",
|
|
"15318328975 163259 send success\n",
|
|
"13205471255 165897 send success\n",
|
|
"13361503856 167024 send success\n",
|
|
"18954680512 162648 send success\n",
|
|
"13465275185 169518 send success\n",
|
|
"13361522787 165038 send success\n",
|
|
"13054610918 168106 send success\n",
|
|
"18506466571 166937 send success\n",
|
|
"13181854171 168902 send success\n",
|
|
"13210388535 161024 send success\n",
|
|
"13306475903 163160 send success\n",
|
|
"15965465758 165241 send success\n",
|
|
"13355460615 165670 send success\n",
|
|
"18266665051 162679 send success\n",
|
|
"13054600511 164526 send success\n",
|
|
"15314325556 163645 send success\n",
|
|
"13963355696 163275 send success\n",
|
|
"13081417578 168653 send success\n",
|
|
"15965466030 165723 send success\n",
|
|
"15254639986 164920 send success\n",
|
|
"13792069959 163204 send success\n",
|
|
"13905465022 165792 send success\n",
|
|
"17754629228 164810 send success\n",
|
|
"15154623768 166814 send success\n",
|
|
"15965466216 164150 send success\n",
|
|
"13864785309 162097 send success\n",
|
|
"15990986892 169407 send success\n",
|
|
"18764586870 168719 send success\n",
|
|
"15315038808 165184 send success\n",
|
|
"18562961530 169036 send success\n",
|
|
"13054673678 167120 send success\n",
|
|
"13706470006 165769 send success\n",
|
|
"13954696798 163164 send success\n",
|
|
"18766719018 162109 send success\n",
|
|
"17754629160 162709 send success\n",
|
|
"15954759855 162859 send success\n",
|
|
"13375461776 164270 send success\n",
|
|
"15954671399 168275 send success\n",
|
|
"18954680397 161083 send success\n",
|
|
"13561016489 164631 send success\n",
|
|
"18860673506 163906 send success\n",
|
|
"15665876948 165219 send success\n",
|
|
"17754629197 167890 send success\n",
|
|
"18865467781 167148 send success\n",
|
|
"17754629133 161483 send success\n",
|
|
"17754600676 166370 send success\n",
|
|
"13561086165 164165 send success\n",
|
|
"15605469730 164137 send success\n",
|
|
"17754629176 161527 send success\n",
|
|
"13220505818 160537 send success\n",
|
|
"15154655057 168761 send success\n",
|
|
"15275640625 164391 send success\n",
|
|
"13562257108 165483 send success\n",
|
|
"15318382108 160973 send success\n",
|
|
"13625462769 167350 send success\n",
|
|
"17754600760 169176 send success\n",
|
|
"13006548466 162870 send success\n",
|
|
"18954676358 167032 send success\n",
|
|
"15552779321 163867 send success\n",
|
|
"13563395385 164018 send success\n",
|
|
"19854689027 164520 send success\n",
|
|
"17754629226 169251 send success\n",
|
|
"13406089611 168925 send success\n",
|
|
"17754665865 161576 send success\n",
|
|
"13963351053 160826 send success\n",
|
|
"17754629175 162306 send success\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"import time\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"dw_jc = \"山东东营陈庄镇测试者\"\n",
|
|
"filename = 'data/陈庄检测人员.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 250226\n",
|
|
"myquery = { \"place_id\": place_id }\n",
|
|
"for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n",
|
|
" code = int(x['fn'].split('-')[0])\n",
|
|
" if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():\n",
|
|
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code'],'name':x['fn']}\n",
|
|
" else:\n",
|
|
" print('no phone')\n",
|
|
"#print(dict2)\n",
|
|
"#dw_jc = \"北体体质康健班测试者\"\n",
|
|
"#dict2 = {375: {'phone': '13793180751', 'code': '0379208'}}\n",
|
|
"for k, v in dict2.items():\n",
|
|
" phone = '+86'+v['phone']\n",
|
|
" yzm = v['code']\n",
|
|
" try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 60 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.SendSmsRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" req.SignName = \"坤铭教育\"\n",
|
|
" req.TemplateId = \"1875765\" \n",
|
|
" req.TemplateParamSet = [dw_jc,yzm]\n",
|
|
" req.PhoneNumberSet = [phone]\n",
|
|
" req.SessionContext = \"\"\n",
|
|
" req.ExtendCode = \"\"\n",
|
|
" req.SenderId = \"\"\n",
|
|
" resp = client.SendSms(req)\n",
|
|
" dict3 = json.loads(resp.to_json_string(indent=2))\n",
|
|
" print(v['phone'], v['code'],dict3['SendStatusSet'][0][\"Message\"])\n",
|
|
" time.sleep(5)\n",
|
|
" except TencentCloudSDKException as err:\n",
|
|
" print(v['phone'],err)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "df637ce6-7c35-404a-af43-2a5a66b49ba0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"dict1 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"print(dict1['SendStatusSet'][0][\"Message\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "feb02430-8946-4ed2-a99b-7f5106257c8b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 单个发送短信"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "25a269c3-758f-4e79-ae6d-a6e6f161d64b",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-12-23T05:38:55.858379Z",
|
|
"iopub.status.busy": "2024-12-23T05:38:55.857680Z",
|
|
"iopub.status.idle": "2024-12-23T05:38:56.119988Z",
|
|
"shell.execute_reply": "2024-12-23T05:38:56.118643Z",
|
|
"shell.execute_reply.started": "2024-12-23T05:38:55.858311Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"+8613793180751 send success\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"dw_jc = \"北体体质康健班学员\"\n",
|
|
"filename = 'data/北体体质康健班202412.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 141002\n",
|
|
"myquery = { \"place_id\": place_id }\n",
|
|
"for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n",
|
|
" code = int(x['fn'].split('-')[0])\n",
|
|
" if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():\n",
|
|
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code'],'name':x['fn']}\n",
|
|
" else:\n",
|
|
" print('no phone')\n",
|
|
"\n",
|
|
"phone = '+86'+'13793180751'\n",
|
|
"yzm = '155673'\n",
|
|
"try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 60 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.SendSmsRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" req.SignName = \"坤铭教育\"\n",
|
|
" req.TemplateId = \"1875765\" \n",
|
|
" req.TemplateParamSet = [dw_jc,yzm]\n",
|
|
" req.PhoneNumberSet = [phone]\n",
|
|
" req.SessionContext = \"\"\n",
|
|
" req.ExtendCode = \"\"\n",
|
|
" req.SenderId = \"\"\n",
|
|
" resp = client.SendSms(req)\n",
|
|
" dict3 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
" print(phone,dict3['SendStatusSet'][0][\"Message\"])\n",
|
|
"except TencentCloudSDKException as err:\n",
|
|
" print(v['phone'],err)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b1e90a59-0b09-4786-99a5-036b69f793ae",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"filename = 'data/中安联合.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 624770\n",
|
|
"myquery = { \"place_id\": place_id,\"code\":\"051067\" }\n",
|
|
"for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n",
|
|
" code = int(x['fn'].split('-')[0])\n",
|
|
" if str(code) in dict1.keys():\n",
|
|
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code']}\n",
|
|
" else:\n",
|
|
" print('no phone')\n",
|
|
"print(dict2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "458f1022-ceb9-49f9-b699-3fcc81658335",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 统计短信发送状态"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "411e89ed-8bb2-478b-b180-52188f800adc",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"\n",
|
|
"try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 60 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.SendStatusStatisticsRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" \n",
|
|
" # 拉取最大条数,最多100条\n",
|
|
" req.Limit = 100\n",
|
|
" # 偏移量 注:目前固定设置为0\n",
|
|
" req.Offset = 0\n",
|
|
" # 开始时间,yyyymmddhh 需要拉取的起始时间,精确到小时\n",
|
|
" req.BeginTime = \"2023112700\"\n",
|
|
" # 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时\n",
|
|
" # 注:EndTime 必须大于 BeginTime\n",
|
|
" req.EndTime = \"2023112723\"\n",
|
|
"\n",
|
|
"\n",
|
|
" # 通过client对象调用SendStatusStatistics方法发起请求。注意请求方法名与请求对象是对应的。\n",
|
|
" # 返回的resp是一个SendStatusStatisticsResponse类的实例,与请求对象对应。\n",
|
|
" resp = client.SendStatusStatistics(req)\n",
|
|
"\n",
|
|
"\n",
|
|
" # 输出json格式的字符串回包\n",
|
|
" print(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
"\n",
|
|
"except TencentCloudSDKException as err:\n",
|
|
" print(err)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "51c61809-e6a3-489e-bac7-f439b673dcd3",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 拉取短信下发状态"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "50183bba-2f9d-4003-98a7-0ecda96670ef",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 60 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.PullSmsSendStatusRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" req.Limit = 100\n",
|
|
" resp = client.PullSmsSendStatus(req)\n",
|
|
" # 输出json格式的字符串回包\n",
|
|
" print(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
"\n",
|
|
"except TencentCloudSDKException as err:\n",
|
|
" print(err)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c3b4d384-9f83-4c91-98aa-0bb1f0e1d4ed",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "68f838e6-5c5c-4b7a-ae78-c2117455d5ed",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|