Added POST Create New WechatMessage API 2

pull/102/head
tianlinzhong 2021-12-23 16:11:54 +08:00
parent 1d88799907
commit 289a6439e8
2 changed files with 40 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"info": { "info": {
"_postman_id": "275f5f12-078c-421a-a050-f054e344dc2b", "_postman_id": "10c28155-4a57-4951-b80e-9893a2edb0d0",
"name": "MyEMS", "name": "MyEMS",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
}, },
@ -2205,6 +2205,21 @@
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
], ],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/home/zhongtianlin/offline_meter_data.xlsx"
},
{
"key": "req",
"value": "{\"data\":{\"rule_id\":1, \"recipient_name\":\"Yinghao Huang\", \"recipient_email\":\"yinghao.huang@qq.com\", \"subject\":\"report_01_2021年10月24日\", \"message\":\"report_01_2021年10月24日\", \"created_datetime\":\"2021-11-01T00:00:00\", \"scheduled_datetime\":\"2021-11-01T00:00:00\"}}",
"type": "text"
}
]
},
"url": { "url": {
"raw": "{{base_url}}/emailmessages", "raw": "{{base_url}}/emailmessages",
"host": [ "host": [
@ -8876,6 +8891,10 @@
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
], ],
"body": {
"mode": "raw",
"raw": "{\"data\":{\"rule_id\":1, \"recipient_name\":\"Yinghao Huang\", \"recipient_mobile\":\"12345678912\", \"message\":\"report_01_2021年10月24日\", \"acknowledge_code\":\"9e52ad6d-3d80-403c-a525-40\", \"created_datetime\":\"2021-11-01T00:00:00\", \"scheduled_datetime\":\"2021-11-01T00:00:00\"}}"
},
"url": { "url": {
"raw": "{{base_url}}/textmessages", "raw": "{{base_url}}/textmessages",
"host": [ "host": [
@ -9831,6 +9850,10 @@
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
], ],
"body": {
"mode": "raw",
"raw": "{\"data\":{\"rule_id\":1, \"recipient_name\":\"SPACE01\", \"recipient_openid\":\"oia2TjuEGTNoeX76QEjQNrcURxG8\", \"message_template_id\":\"Doclyl5uP7Aciu-qZ7mJNPtWkbkYnWBWVja26EGbNyk\", \"message_data\":\"{\\\"space_id\\\":1, \\\"high_limit\\\":1000.000}\", \"acknowledge_code\":\"9e52ad6d\", \"created_datetime\":\"2021-11-01T00:00:00\", \"scheduled_datetime\":\"2021-11-01T00:00:00\"}}"
},
"url": { "url": {
"raw": "{{base_url}}/wechatmessages", "raw": "{{base_url}}/wechatmessages",
"host": [ "host": [
@ -12790,5 +12813,11 @@
] ]
} }
} }
],
"variable": [
{
"value": "",
"disabled": true
}
] ]
} }

View File

@ -1,3 +1,4 @@
import re
import falcon import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
@ -124,6 +125,11 @@ class WechatMessageCollection(object):
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_RECIPIENT_OPENID') description='API.INVALID_RECIPIENT_OPENID')
recipient_openid = str.strip(new_values['data']['recipient_openid']) recipient_openid = str.strip(new_values['data']['recipient_openid'])
match = re.match(r'^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z-_]{28}$', recipient_openid)
if match is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_OPENID')
if 'message_template_id' not in new_values['data'].keys() or \ if 'message_template_id' not in new_values['data'].keys() or \
not isinstance(new_values['data']['message_template_id'], str) or \ not isinstance(new_values['data']['message_template_id'], str) or \
@ -131,6 +137,10 @@ class WechatMessageCollection(object):
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_MESSAGE_TEMPLATE_ID') description='API.INVALID_MESSAGE_TEMPLATE_ID')
message_template_id = str.strip(new_values['data']['message_template_id']) message_template_id = str.strip(new_values['data']['message_template_id'])
match = re.match(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\w-]{43}$', message_template_id)
if match is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_TEMPLATE_ID')
if 'message_data' not in new_values['data'].keys() or \ if 'message_data' not in new_values['data'].keys() or \
not isinstance(new_values['data']['message_data'], str) or \ not isinstance(new_values['data']['message_data'], str) or \