Skip to content

Commit

Permalink
Added POST Create New WechatMessage API 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tianlinzhong committed Dec 23, 2021
1 parent 1d88799 commit 289a643
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
31 changes: 30 additions & 1 deletion myems-api/MyEMS.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "275f5f12-078c-421a-a050-f054e344dc2b",
"_postman_id": "10c28155-4a57-4951-b80e-9893a2edb0d0",
"name": "MyEMS",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -2205,6 +2205,21 @@
"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\":\"[email protected]\", \"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": {
"raw": "{{base_url}}/emailmessages",
"host": [
Expand Down Expand Up @@ -8876,6 +8891,10 @@
"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": {
"raw": "{{base_url}}/textmessages",
"host": [
Expand Down Expand Up @@ -9831,6 +9850,10 @@
"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": {
"raw": "{{base_url}}/wechatmessages",
"host": [
Expand Down Expand Up @@ -12790,5 +12813,11 @@
]
}
}
],
"variable": [
{
"value": "",
"disabled": true
}
]
}
10 changes: 10 additions & 0 deletions myems-api/core/wechatmessage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import falcon
import simplejson as json
import mysql.connector
Expand Down Expand Up @@ -124,13 +125,22 @@ def on_post(req, resp):
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_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 \
not isinstance(new_values['data']['message_template_id'], str) or \
len(str.strip(new_values['data']['message_template_id'])) == 0:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_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 \
not isinstance(new_values['data']['message_data'], str) or \
Expand Down

0 comments on commit 289a643

Please sign in to comment.