This commit is contained in:
512song committed 2023-11-27 17:54:04 +08:00
1 parent 3b4acc857c
commit 2d6db59b1c
4 files changed
+350 -117

No files matched your search

+102 -70
View File
@@ -23,8 +23,8 @@
"mydb = myclient[\"baogao\"]\n",
"mycol = mydb[\"place\"]\n",
"\n",
"id = 624770\n",
"name = \"淄博世纪花园\"\n",
"id = 698465\n",
"name = \"淄博积家村\"\n",
"myquery = { \"id\": id }\n",
"num = mycol.count_documents(myquery)\n",
"if num>0:\n",
@@ -63,9 +63,9 @@
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"baogao\"]\n",
"\n",
"place_id = 624770\n",
"place_code = '05'\n",
"dw_name = '淄博世纪花园'\n",
"place_id = 698465\n",
"place_code = '06'\n",
"dw_name = '淄博积家村'\n",
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n",
"fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n",
"\n",
@@ -78,7 +78,7 @@
"while i < len(fls):\n",
" code = random.sample(code_list,4) #随机取4位数\n",
" code_num = ''.join(code) \n",
" if code_num not in list1:\n",
" if place_code+code_num not in list1:\n",
" list1.append(place_code+code_num)\n",
" i +=1\n",
"i = 0\n",
@@ -97,12 +97,12 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "767cdc9b-310e-4922-8b7d-3581a328cf45",
"cell_type": "markdown",
"id": "ad9e943a-bb3a-4d58-93ef-cc442a80effa",
"metadata": {},
"outputs": [],
"source": []
"source": [
"## 批量发送短信(测试)"
]
},
{
"cell_type": "code",
@@ -113,6 +113,11 @@
},
"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",
@@ -120,20 +125,50 @@
"mydb = myclient[\"baogao\"]\n",
"mycol = mydb[\"pdf\"]\n",
"\n",
"filename = 'data/世纪花园人员信息.json'\n",
"filename = 'data/积家村报告明细.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"place_id = 624770\n",
"place_id = 698465\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():\n",
" dict2[code] = {'name':str(dict1[str(code)]['name']),'phone':str(dict1[str(code)]['phone']),'code':x['code']}\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']}\n",
" else:\n",
" print(code,'no phone')\n",
"for k,v in dict2.items():\n",
" print(k,v['name'],v['phone'],v['code'])"
"#print(dict2)\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 = [\"淄博积家村体测者\",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",
" except TencentCloudSDKException as err:\n",
" print(v['phone'],err)"
]
},
{
@@ -169,7 +204,7 @@
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"place_id = 624770\n",
"place_id = 698465\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",
@@ -200,7 +235,7 @@
" req.SmsSdkAppId = \"1400140089\"\n",
" req.SignName = \"坤铭教育\"\n",
" req.TemplateId = \"1875765\" \n",
" req.TemplateParamSet = [\"淄博世纪花园体测者\",yzm]\n",
" req.TemplateParamSet = [\"淄博积家村体测者\",yzm]\n",
" req.PhoneNumberSet = [phone]\n",
" req.SessionContext = \"\"\n",
" req.ExtendCode = \"\"\n",
@@ -234,12 +269,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 86,
"id": "25a269c3-758f-4e79-ae6d-a6e6f161d64b",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-27T03:02:47.586339Z",
"iopub.status.busy": "2023-11-27T03:02:47.585869Z",
"iopub.status.idle": "2023-11-27T03:02:47.873412Z",
"shell.execute_reply": "2023-11-27T03:02:47.872245Z",
"shell.execute_reply.started": "2023-11-27T03:02:47.586301Z"
},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+8618264313303 send success\n"
]
}
],
"source": [
"from tencentcloud.common import credential\n",
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
@@ -249,56 +299,38 @@
"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\":\"053618\" }\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)\n",
"\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 = [\"淄博世纪花园体测者\",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",
"phone = '+86'+'18264313303'\n",
"yzm = '066357'\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 = [\"淄博积家村体测者\",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",
" except TencentCloudSDKException as err:\n",
" print(v['phone'],err)"
" print(phone,dict3['SendStatusSet'][0][\"Message\"])\n",
"except TencentCloudSDKException as err:\n",
" print(v['phone'],err)"
]
},
{
@@ -384,10 +416,10 @@
" # 偏移量 注:目前固定设置为0\n",
" req.Offset = 0\n",
" # 开始时间,yyyymmddhh 需要拉取的起始时间,精确到小时\n",
" req.BeginTime = \"2023111000\"\n",
" req.BeginTime = \"2023112700\"\n",
" # 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时\n",
" # 注:EndTime 必须大于 BeginTime\n",
" req.EndTime = \"2023111023\"\n",
" req.EndTime = \"2023112723\"\n",
"\n",
"\n",
" # 通过client对象调用SendStatusStatistics方法发起请求。注意请求方法名与请求对象是对应的。\n",