657 lines
24 KiB
Plaintext
657 lines
24 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e6dcc663-e0ed-4ea3-b442-11f229f4af94",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 新增体测单位"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"id": "360f0a97-d73d-43f3-9f7a-0f9582103c82",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-20T09:18:01.505731Z",
|
|
"iopub.status.busy": "2025-03-20T09:18:01.504944Z",
|
|
"iopub.status.idle": "2025-03-20T09:18:01.519437Z",
|
|
"shell.execute_reply": "2025-03-20T09:18:01.518406Z",
|
|
"shell.execute_reply.started": "2025-03-20T09:18:01.505657Z"
|
|
},
|
|
"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 = 25032001\n",
|
|
"place_code = \"20\"\n",
|
|
"dw_name = \"2025级油田老年大学体质康健基础班\"\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": 24,
|
|
"id": "6ce2cbc7-435a-461c-bdb8-abd9a6962fbc",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-20T09:19:55.399000Z",
|
|
"iopub.status.busy": "2025-03-20T09:19:55.398328Z",
|
|
"iopub.status.idle": "2025-03-20T09:19:55.423109Z",
|
|
"shell.execute_reply": "2025-03-20T09:19:55.422235Z",
|
|
"shell.execute_reply.started": "2025-03-20T09:19:55.398942Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"31 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 = 25032001\n",
|
|
"place_code = \"20\"\n",
|
|
"dw_name = \"2025级油田老年大学体质康健基础班\"\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": 25,
|
|
"id": "5f665c0f-8d30-4759-b7f8-fb7e13b98efa",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-20T09:20:14.292047Z",
|
|
"iopub.status.busy": "2025-03-20T09:20:14.291517Z",
|
|
"iopub.status.idle": "2025-03-20T09:20:14.320715Z",
|
|
"shell.execute_reply": "2025-03-20T09:20:14.319854Z",
|
|
"shell.execute_reply.started": "2025-03-20T09:20:14.291999Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1 18654628632 0028-张红丽.pdf 206138\n",
|
|
"2 13589980155 0032-马建辉.pdf 208451\n",
|
|
"3 13963394816 0029-张凤魁.pdf 205879\n",
|
|
"4 13905462350 0034-张晓云.pdf 203015\n",
|
|
"5 13562280825 0016-李爱云.pdf 200689\n",
|
|
"6 15318339058 0007-韩金秀.pdf 203970\n",
|
|
"7 13589956960 0026-严新杰.pdf 200467\n",
|
|
"8 13906478916 0003-曹春梅.pdf 205019\n",
|
|
"9 13706476046 0023-王维卿.pdf 208975\n",
|
|
"10 13561090015 0022-王金文.pdf 204916\n",
|
|
"11 13013569039 0006-耿红霞.pdf 209158\n",
|
|
"12 13954622371 0019-王国臣.pdf 204637\n",
|
|
"13 18905466915 0017-梁秀荣.pdf 208243\n",
|
|
"14 13012902582 0030-张明霞.pdf 203281\n",
|
|
"15 13954626181 0013-李佐东.pdf 202568\n",
|
|
"16 13287350839 0020-王秀娟.pdf 200195\n",
|
|
"17 13954654611 0035-单丽荣.pdf 205740\n",
|
|
"18 13792079628 0031-马羚.pdf 201534\n",
|
|
"19 13563378335 0027-赵芳霞.pdf 205462\n",
|
|
"20 15105461296 0001-丛霞.pdf 203872\n",
|
|
"21 18653699898 0025-杨江萍.pdf 204830\n",
|
|
"22 13082601667 0021-王静.pdf 207801\n",
|
|
"23 13954606669 0033-朱莲女.pdf 207605\n",
|
|
"24 13864757610 0036-赵萍.pdf 208520\n",
|
|
"25 13287336162 0012-鲁兴湘.pdf 200654\n",
|
|
"26 13325052019 0010-刘敏.pdf 200635\n",
|
|
"27 13589965775 0011-李梅.pdf 206794\n",
|
|
"28 13864739068 0018-孙杰.pdf 203096\n",
|
|
"29 15105461298 0002-陈秀华.pdf 205248\n",
|
|
"30 15550503986 0005-丁元花.pdf 201624\n",
|
|
"31 15005463621 0037-高学晖.pdf 206374\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 = \"2025级油田老年大学体质康健基础班\"\n",
|
|
"filename = 'data/2025级油田老年大学体质康健基础班.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 25032001\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": 26,
|
|
"id": "4b2b5d76-665f-4dfe-bbd3-5c80abd8c3e3",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-03-20T09:20:55.440081Z",
|
|
"iopub.status.busy": "2025-03-20T09:20:55.439083Z",
|
|
"iopub.status.idle": "2025-03-20T09:23:36.769544Z",
|
|
"shell.execute_reply": "2025-03-20T09:23:36.768167Z",
|
|
"shell.execute_reply.started": "2025-03-20T09:20:55.440022Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"18654628632 206138 send success\n",
|
|
"13589980155 208451 send success\n",
|
|
"13963394816 205879 send success\n",
|
|
"13905462350 203015 send success\n",
|
|
"13562280825 200689 send success\n",
|
|
"15318339058 203970 send success\n",
|
|
"13589956960 200467 send success\n",
|
|
"13906478916 205019 send success\n",
|
|
"13706476046 208975 send success\n",
|
|
"13561090015 204916 send success\n",
|
|
"13013569039 209158 send success\n",
|
|
"13954622371 204637 send success\n",
|
|
"18905466915 208243 send success\n",
|
|
"13012902582 203281 send success\n",
|
|
"13954626181 202568 send success\n",
|
|
"13287350839 200195 send success\n",
|
|
"13954654611 205740 send success\n",
|
|
"13792079628 201534 send success\n",
|
|
"13563378335 205462 send success\n",
|
|
"15105461296 203872 send success\n",
|
|
"18653699898 204830 send success\n",
|
|
"13082601667 207801 send success\n",
|
|
"13954606669 207605 send success\n",
|
|
"13864757610 208520 send success\n",
|
|
"13287336162 200654 send success\n",
|
|
"13325052019 200635 send success\n",
|
|
"13589965775 206794 send success\n",
|
|
"13864739068 203096 send success\n",
|
|
"15105461298 205248 send success\n",
|
|
"15550503986 201624 send success\n",
|
|
"15005463621 206374 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/2025级油田老年大学体质康健基础班.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 25032001\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": null,
|
|
"id": "25a269c3-758f-4e79-ae6d-a6e6f161d64b",
|
|
"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",
|
|
"dw_jc = \"海淀区老干部大学\"\n",
|
|
"filename = 'data/海淀区老干部大学第一期.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 250319\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 = '185679'\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
|
|
}
|