@@ -5,9 +5,17 @@ from __future__ import division |
||
| 5 | 5 |
from django_logit import logit |
| 6 | 6 |
from django.conf import settings |
| 7 | 7 |
from django_response import response |
| 8 |
+from TimeConvert import TimeConvert as tc |
|
| 8 | 9 |
|
| 10 |
+from pywe_template_message import send_template_message |
|
| 11 |
+ |
|
| 12 |
+from account.models import UserInfo |
|
| 9 | 13 |
from household.models import HouseholdThermometerMeasureLogInfo, HouseholdThermometerEquipmentBindInfo |
| 10 | 14 |
|
| 15 |
+ |
|
| 16 |
+logger = logging.getLogger('console')
|
|
| 17 |
+ |
|
| 18 |
+ |
|
| 11 | 19 |
@logit |
| 12 | 20 |
def mp_bind_thermometer(request): |
| 13 | 21 |
user_id = request.POST.get('user_id', '')
|
@@ -18,6 +26,7 @@ def mp_bind_thermometer(request): |
||
| 18 | 26 |
return response() |
| 19 | 27 |
|
| 20 | 28 |
|
| 29 |
+@logit |
|
| 21 | 30 |
def mp_thermometer_list(request): |
| 22 | 31 |
user_id = request.POST.get('user_id', '')
|
| 23 | 32 |
eqpts = HouseholdThermometerEquipmentBindInfo.objects.filter(user_id=user_id, status=True) |
@@ -29,6 +38,7 @@ def mp_thermometer_list(request): |
||
| 29 | 38 |
}) |
| 30 | 39 |
|
| 31 | 40 |
|
| 41 |
+@logit |
|
| 32 | 42 |
def mp_upload_temperature(request): |
| 33 | 43 |
user_id = request.POST.get('user_id', '')
|
| 34 | 44 |
macid = request.POST.get('macid', '')
|
@@ -36,9 +46,49 @@ def mp_upload_temperature(request): |
||
| 36 | 46 |
|
| 37 | 47 |
HouseholdThermometerMeasureLogInfo.objects.create(user_id=user_id, macid=macid, temperature=temperature) |
| 38 | 48 |
|
| 49 |
+ userids = HouseholdThermometerEquipmentBindInfo.objects.values_list('user_id', flat=True).filter(macid=macid, status=True)
|
|
| 50 |
+ |
|
| 51 |
+ wxcfg = settings.WECHAT.get('JSAPI', {})
|
|
| 52 |
+ appid = wxcfg.get('appID')
|
|
| 53 |
+ secret = wxcfg.get('appsecret')
|
|
| 54 |
+ |
|
| 55 |
+ wxcfg = settings.WECHAT.get('MINIAPP', {})
|
|
| 56 |
+ miniappid = wxcfg.get('appID')
|
|
| 57 |
+ |
|
| 58 |
+ users = UserInfo.objects.filter(user_id__in=userids) |
|
| 59 |
+ |
|
| 60 |
+ data = {
|
|
| 61 |
+ "first": {
|
|
| 62 |
+ "value": u'你的家人测温了,请查收~~~', |
|
| 63 |
+ "color": "#173177" |
|
| 64 |
+ }, |
|
| 65 |
+ "product": {
|
|
| 66 |
+ "value": macid, |
|
| 67 |
+ "color": "#173177" |
|
| 68 |
+ }, |
|
| 69 |
+ "price": {
|
|
| 70 |
+ "value": temperature, |
|
| 71 |
+ "color": "#173177" |
|
| 72 |
+ }, |
|
| 73 |
+ "time": {
|
|
| 74 |
+ "value": tc.local_string(), |
|
| 75 |
+ "color": "#173177" |
|
| 76 |
+ }, |
|
| 77 |
+ "remark": {
|
|
| 78 |
+ "value": u'感谢你的使用', |
|
| 79 |
+ "color": "#173177" |
|
| 80 |
+ } |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ for user in users: |
|
| 84 |
+ res = send_template_message(user_id=user.openid, template_id=settings.TEMPLATE_ID_HOUSEHOLD_THERMOMETER_MEASURE, data=data, miniappid=miniappid, minipagepath='/pages/index/index', appid=appid, secret=secret, storage=RedisStorage(r)) |
|
| 85 |
+ |
|
| 86 |
+ logger.info(res) |
|
| 87 |
+ |
|
| 39 | 88 |
return response() |
| 40 | 89 |
|
| 41 | 90 |
|
| 91 |
+@logit |
|
| 42 | 92 |
def mp_temperature_list(request): |
| 43 | 93 |
user_id = request.POST.get('user_id', '')
|
| 44 | 94 |
macid = request.POST.get('macid', '')
|
@@ -5,3 +5,4 @@ pywe-qrcode==1.0.3 |
||
| 5 | 5 |
pywe-storage==1.0.1 |
| 6 | 6 |
pywe-token==1.3.1 |
| 7 | 7 |
pywe-user==1.0.4 |
| 8 |
+pywe-template-message==1.0.1 |
@@ -321,6 +321,9 @@ MAKE_PASSWORD_HASHER = 'pbkdf2_sha256' |
||
| 321 | 321 |
# 体温检测 |
| 322 | 322 |
FEVER_TEMPERATURE = 37.3 |
| 323 | 323 |
|
| 324 |
+# 微信模版消息/订阅消息 |
|
| 325 |
+TEMPLATE_ID_HOUSEHOLD_THERMOMETER_MEASURE = 'O0avKAbMvyctezo9HSbU836ye1GER_svToZ6kKNAevk' |
|
| 326 |
+ |
|
| 324 | 327 |
# 开发调试相关配置 |
| 325 | 328 |
if DEBUG: |
| 326 | 329 |
try: |