This commit is contained in:
512song committed 2023-11-11 22:46:28 +08:00
1 parent bb45950ba6
commit bec78cd290
4 files changed
+394 -193

No files matched your search

+247 -40
View File
@@ -23,8 +23,8 @@
"mydb = myclient[\"baogao\"]\n",
"mycol = mydb[\"place\"]\n",
"\n",
"id = 469849\n",
"name = \"长炼医院\"\n",
"id = 624770\n",
"name = \"淄博世纪花园\"\n",
"myquery = { \"id\": id }\n",
"num = mycol.count_documents(myquery)\n",
"if num>0:\n",
@@ -63,14 +63,9 @@
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"baogao\"]\n",
"\n",
"\n",
"filename = 'data/北京农行人员名单all.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"place_id = 309118\n",
"place_code = '03'\n",
"dw_name = '中国农业银行股份有限公司北京市分行'\n",
"place_id = 624770\n",
"place_code = '05'\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",
@@ -81,7 +76,7 @@
"list1 = []\n",
"i = 0\n",
"while i < len(fls):\n",
" code = random.sample(code_list,5) #随机取6位数\n",
" code = random.sample(code_list,4) #随机取4位数\n",
" code_num = ''.join(code) \n",
" if code_num not in list1:\n",
" list1.append(place_code+code_num)\n",
@@ -125,19 +120,20 @@
"mydb = myclient[\"baogao\"]\n",
"mycol = mydb[\"pdf\"]\n",
"\n",
"filename = 'data/北京农行人员名单all.json'\n",
"filename = 'data/世纪花园人员信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"place_id = 309118\n",
"place_id = 624770\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] = {'phone':str(dict1[str(code)]['phone']),'code':x['code']}\n",
" dict2[code] = {'name':str(dict1[str(code)]['name']),'phone':str(dict1[str(code)]['phone']),'code':x['code']}\n",
" else:\n",
" print('no phone')\n",
"print(dict2)"
" print(code,'no phone')\n",
"for k,v in dict2.items():\n",
" print(k,v['name'],v['phone'],v['code'])"
]
},
{
@@ -169,11 +165,11 @@
"mydb = myclient[\"baogao\"]\n",
"mycol = mydb[\"pdf\"]\n",
"\n",
"filename = 'data/北京农行人员名单all.json'\n",
"filename = 'data/世纪花园人员信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"place_id = 309118\n",
"place_id = 624770\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",
@@ -181,7 +177,7 @@
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code']}\n",
" else:\n",
" print('no phone')\n",
"print(dict2)\n",
"#print(dict2)\n",
"\n",
"#dict2 = {375: {'phone': '13793180751', 'code': '0379208'}}\n",
"for k, v in dict2.items():\n",
@@ -193,7 +189,7 @@
" cred = credential.Credential(secretId, secretKey) \n",
" httpProfile = HttpProfile()\n",
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
" httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)\n",
" httpProfile.reqTimeout = 60 # 请求超时时间,单位为秒(默认60秒)\n",
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
" clientProfile = ClientProfile()\n",
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
@@ -204,7 +200,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",
@@ -217,24 +213,6 @@
" print(v['phone'],err)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eefec974-c4b7-43c8-82c2-6ad6e5045aa0",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"filename = 'data/01.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"for k, v in dict1.items():\n",
" phone = '+86'+v['phone']\n",
" yzm = v['code']\n",
" print(k,phone,yzm)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -246,10 +224,239 @@
"print(dict1['SendStatusSet'][0][\"Message\"])"
]
},
{
"cell_type": "markdown",
"id": "feb02430-8946-4ed2-a99b-7f5106257c8b",
"metadata": {},
"source": [
"## 单个发送短信"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba05bd1a-9f33-4df7-b15e-d110c19a5dea",
"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",
"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",
"\n",
" print(v['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 = \"2023111000\"\n",
" # 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时\n",
" # 注:EndTime 必须大于 BeginTime\n",
" req.EndTime = \"2023111023\"\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": []