752 lines
28 KiB
Plaintext
752 lines
28 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": "2024-12-23T02:35:15.481801Z",
|
|
"iopub.status.busy": "2024-12-23T02:35:15.481073Z",
|
|
"iopub.status.idle": "2024-12-23T02:35:15.588908Z",
|
|
"shell.execute_reply": "2024-12-23T02:35:15.588281Z",
|
|
"shell.execute_reply.started": "2024-12-23T02:35:15.481732Z"
|
|
},
|
|
"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 = 141002\n",
|
|
"place_code = \"15\"\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": 3,
|
|
"id": "6ce2cbc7-435a-461c-bdb8-abd9a6962fbc",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-12-23T02:37:43.114677Z",
|
|
"iopub.status.busy": "2024-12-23T02:37:43.113786Z",
|
|
"iopub.status.idle": "2024-12-23T02:37:43.138884Z",
|
|
"shell.execute_reply": "2024-12-23T02:37:43.138013Z",
|
|
"shell.execute_reply.started": "2024-12-23T02:37:43.114598Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"71 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 = 141002\n",
|
|
"place_code = \"15\"\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": 6,
|
|
"id": "5f665c0f-8d30-4759-b7f8-fb7e13b98efa",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-12-23T05:43:17.023291Z",
|
|
"iopub.status.busy": "2024-12-23T05:43:17.022726Z",
|
|
"iopub.status.idle": "2024-12-23T05:43:17.056324Z",
|
|
"shell.execute_reply": "2024-12-23T05:43:17.055498Z",
|
|
"shell.execute_reply.started": "2024-12-23T05:43:17.023237Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1 15552778879 87-韩秋春.pdf 157481\n",
|
|
"2 13176607576 40-聂秋香.pdf 150269\n",
|
|
"3 13515466253 20-成桂艳.pdf 154130\n",
|
|
"4 13356838977 45-齐立红.pdf 159017\n",
|
|
"5 15505463267 6-刘来珍.pdf 151957\n",
|
|
"6 15618032716 72-林娟.pdf 153582\n",
|
|
"7 13001564985 23-李慧珠.pdf 153760\n",
|
|
"8 13854609739 85-连海燕.pdf 156827\n",
|
|
"9 13605461196 50-刘瑛.pdf 159238\n",
|
|
"10 13697833655 48-刘其英.pdf 157409\n",
|
|
"11 18654608681 68-张桂芝.pdf 157534\n",
|
|
"12 13561099637 9-吕建国.pdf 157281\n",
|
|
"13 13589970661 30-王争华.pdf 151934\n",
|
|
"14 15666215813 5-刘晓红.pdf 152476\n",
|
|
"15 15954638716 41-胡桂凤.pdf 153278\n",
|
|
"16 13793983616 80-董希娥.pdf 150362\n",
|
|
"17 18661395568 56-娄金华.pdf 153028\n",
|
|
"18 15006966879 38-耿宏勋.pdf 154872\n",
|
|
"19 13006548397 15-宋立君.pdf 155673\n",
|
|
"20 13054610560 88-马国丽.pdf 153905\n",
|
|
"21 13864711691 11-吴晓燕.pdf 156580\n",
|
|
"22 13013569039 39-耿红霞.pdf 155263\n",
|
|
"23 13356615748 17-张桂荣.pdf 150152\n",
|
|
"24 13589961337 35-王霞.pdf 152574\n",
|
|
"25 13678611392 34-王金美.pdf 152549\n",
|
|
"26 13963356165 31-王春爱.pdf 156502\n",
|
|
"27 13589986778 26-杨素华.pdf 158590\n",
|
|
"28 13361512362 77-秦春霞.pdf 154059\n",
|
|
"29 13054658622 86-郗桂红.pdf 157145\n",
|
|
"30 18661378656 54-周春萍.pdf 154763\n",
|
|
"31 15154636366 25-李红霞.pdf 156873\n",
|
|
"32 18654698789 37-罗秀艳.pdf 150825\n",
|
|
"33 13054652092 8-卢霞.pdf 159367\n",
|
|
"34 15610063229 7-刘英.pdf 159386\n",
|
|
"35 13963359769 1-万秀香.pdf 156540\n",
|
|
"36 18554659267 47-任大华.pdf 156039\n",
|
|
"37 18661376637 18-张秀玉.pdf 157206\n",
|
|
"38 18611391991 71-朱兰生.pdf 153617\n",
|
|
"39 13563399566 67-张伟.pdf 158436\n",
|
|
"40 15263888916 36-生月华.pdf 150476\n",
|
|
"41 13210319979 33-王海燕.pdf 155632\n",
|
|
"42 13561020118 84-赵立静.pdf 156825\n",
|
|
"43 13371503039 53-吕鸿义.pdf 159602\n",
|
|
"44 13864791829 75-王翠云.pdf 151079\n",
|
|
"45 18705469686 42-范晓英.pdf 157035\n",
|
|
"46 13706366656 57-孙家祥.pdf 153718\n",
|
|
"47 18554718350 63-宋秀娟.pdf 152087\n",
|
|
"48 13792060709 76-盖荣.pdf 153519\n",
|
|
"49 18860629985 46-于瑞先.pdf 154058\n",
|
|
"50 15314347726 55-姜英.pdf 151762\n",
|
|
"51 13854650187 32-王毅.pdf 159436\n",
|
|
"52 15020597108 78-程茂霞.pdf 153264\n",
|
|
"53 15606470366 73-温建华.pdf 155470\n",
|
|
"54 13945664258 49-刘桂君.pdf 150794\n",
|
|
"55 18554660557 65-巴建云.pdf 154836\n",
|
|
"56 15105468997 14-宋清贤.pdf 151746\n",
|
|
"57 13963370053 16-张德芳.pdf 158790\n",
|
|
"58 13864707888 60-宁振莹.pdf 151487\n",
|
|
"59 13906472659 64-尚国勋.pdf 150875\n",
|
|
"60 13963350118 12-唐慧芳.pdf 152738\n",
|
|
"61 13356645705 29-牛春芳.pdf 153915\n",
|
|
"62 13054625519 89-黄启江.pdf 150912\n",
|
|
"63 15666210207 81-袁庆敏.pdf 157248\n",
|
|
"64 15954620216 44-雒云秀.pdf 156738\n",
|
|
"65 13562277856 22-朱振峰.pdf 155413\n",
|
|
"66 13181996942 70-曹玉英.pdf 151820\n",
|
|
"67 18653699788 27-林乐武.pdf 151893\n",
|
|
"68 13589432668 83-赵福珍.pdf 156124\n",
|
|
"69 13563376888 3-伊茂胜.pdf 156285\n",
|
|
"70 13375466356 13-孟凡业.pdf 150571\n",
|
|
"71 13854664965 4-刘学农.pdf 151763\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/北体体质康健班202412.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": 7,
|
|
"id": "4b2b5d76-665f-4dfe-bbd3-5c80abd8c3e3",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-12-23T05:43:33.444175Z",
|
|
"iopub.status.busy": "2024-12-23T05:43:33.443420Z",
|
|
"iopub.status.idle": "2024-12-23T06:01:33.534050Z",
|
|
"shell.execute_reply": "2024-12-23T06:01:33.532110Z",
|
|
"shell.execute_reply.started": "2024-12-23T05:43:33.444103Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"15552778879 157481 send success\n",
|
|
"13176607576 150269 send success\n",
|
|
"13515466253 154130 send success\n",
|
|
"13356838977 159017 send success\n",
|
|
"15505463267 151957 send success\n",
|
|
"15618032716 153582 send success\n",
|
|
"13001564985 153760 send success\n",
|
|
"13854609739 156827 send success\n",
|
|
"13605461196 159238 send success\n",
|
|
"13697833655 157409 send success\n",
|
|
"18654608681 157534 send success\n",
|
|
"13561099637 157281 send success\n",
|
|
"13589970661 151934 send success\n",
|
|
"15666215813 152476 send success\n",
|
|
"15954638716 153278 send success\n",
|
|
"13793983616 150362 send success\n",
|
|
"18661395568 153028 send success\n",
|
|
"15006966879 154872 send success\n",
|
|
"13006548397 155673 send success\n",
|
|
"13054610560 153905 send success\n",
|
|
"13864711691 156580 send success\n",
|
|
"13013569039 155263 send success\n",
|
|
"13356615748 150152 send success\n",
|
|
"13589961337 152574 send success\n",
|
|
"13678611392 152549 send success\n",
|
|
"13963356165 156502 send success\n",
|
|
"13589986778 158590 send success\n",
|
|
"13361512362 154059 send success\n",
|
|
"13054658622 157145 send success\n",
|
|
"18661378656 154763 send success\n",
|
|
"15154636366 156873 send success\n",
|
|
"18654698789 150825 send success\n",
|
|
"13054652092 159367 send success\n",
|
|
"15610063229 159386 send success\n",
|
|
"13963359769 156540 send success\n",
|
|
"18554659267 156039 send success\n",
|
|
"18661376637 157206 send success\n",
|
|
"18611391991 153617 send success\n",
|
|
"13563399566 158436 send success\n",
|
|
"15263888916 150476 send success\n",
|
|
"13210319979 155632 send success\n",
|
|
"13561020118 156825 send success\n",
|
|
"13371503039 159602 send success\n",
|
|
"13864791829 151079 send success\n",
|
|
"18705469686 157035 send success\n",
|
|
"13706366656 153718 send success\n",
|
|
"18554718350 152087 send success\n",
|
|
"13792060709 153519 send success\n",
|
|
"18860629985 154058 send success\n",
|
|
"15314347726 151762 send success\n",
|
|
"13854650187 159436 send success\n",
|
|
"15020597108 153264 send success\n",
|
|
"15606470366 155470 send success\n",
|
|
"13945664258 150794 send success\n",
|
|
"18554660557 154836 send success\n",
|
|
"15105468997 151746 send success\n",
|
|
"13963370053 158790 send success\n",
|
|
"13864707888 151487 send success\n",
|
|
"13906472659 150875 send success\n",
|
|
"13963350118 152738 send success\n",
|
|
"13356645705 153915 send success\n",
|
|
"13054625519 150912 send success\n",
|
|
"15666210207 157248 send success\n",
|
|
"15954620216 156738 send success\n",
|
|
"13562277856 155413 send success\n",
|
|
"13181996942 151820 send success\n",
|
|
"18653699788 151893 send success\n",
|
|
"13589432668 156124 send success\n",
|
|
"13563376888 156285 send success\n",
|
|
"13375466356 150571 send success\n",
|
|
"13854664965 151763 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/北体体质康健班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",
|
|
"#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(15)\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
|
|
}
|