示例#1
0
    def temp_msg(self):
        news = {
            "touser": "******",
            "template_id": "6S",
            "url": "https://www.baidu.com",
            "data": {
                "first": {
                    "value": "hj"
                },
                "keyword1": {
                    "value": "巧克力"
                },
                "keyword2": {
                    "value": "16516516554185"
                },
                "keyword3": {
                    "value": "65元"
                },
                "keyword4": {
                    "value": "2017年10月15日"
                },
                "remark": {
                    "value": "欢迎再次购买!"
                }
            }
        }

        # o8GV_0bSXP9AX6hqfJdy7tZUeOwM
        news['touser'] = CONF.get('weixin', 'touser')
        news['template_id'] = CONF.get('weixin', 'template_id')
        news['url'] = CONF.get('weixin', 'url')

        news['data']["first"]["value"] = u"恭喜你购买成功!".encode('utf-8')
        news['data']["keyword1"]["value"] = u"SQD设备!".encode('utf-8')
        news['data']["keyword2"]["value"] = u"5165161321513215!".encode(
            'utf-8')
        news['data']["keyword3"]["value"] = u"3500元!".encode('utf-8')
        news['data']["keyword4"]["value"] = u"2017年10月15日".encode('utf-8')
        news['data']["remark"]["value"] = u"欢迎再次购买!".encode('utf-8')

        return news
示例#2
0
# -*- coding: utf-8 -*-

import time
import random
import uuid
from base import BaseHandler, RestHandler
from app.service.luosimao import LuoSiMao
from app.model import Session, User
from app.config import CONF

COOKIE_NAME = CONF.get('general', 'cookie_name')


class SendMobileCode(BaseHandler):
    def gene_text(self):
        number = 6
        source = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
        return ''.join(random.sample(source, number))

    def post(self):
        mobile = self.get_argument('mobile', '')

        if not mobile:
            self.finish({'code': 1, 'msg': u'手机号不能为空'})
            return

        code = self.gene_text()
        data = LuoSiMao().send(mobile, code).sync()

        if data['msg'] == 'ok':
            session = self.util_get_session()
示例#3
0
# -*- coding: utf-8 -*-# filename: basic.py

import urllib
import time
import json

from app.config import CONF
from base import BaseService
from basic import Basic

URL = CONF.get('agent', 'url')


class WeChatService(BaseService):
    method = 'post'
    url = URL + '/wechat'
    base = ''

    # 获取openid 和 session_key
    def get_user_info(self, js_code):
        self.path = '/get_user_info'
        self.p = {
            'js_code': js_code,
        }
        return self

    def temp_send(self, news):
        accessToken = Basic().get_access_token()
        postUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s" % accessToken
        urlResp = urllib.urlopen(postUrl, news)
        urlResp = json.loads(urlResp.read())
示例#4
0
import time
import uuid
import logging
import tornado.web
import os
import sys
from tornado.util import ObjectDict
from tornado.escape import json_decode, json_encode
from sqlalchemy.orm import defer
from sqlalchemy import literal_column, desc, column
from app.config import DBSession
from app.config import CONF
from app.model import User, Session, ActionLog
from util import UtilHandler

COOKIE_NAME = CONF.get('general', 'cookie_name')
DEBUG = CONF.getboolean('general', 'debug')

logger = logging.getLogger('app.base')


class BaseHandler(tornado.web.RequestHandler, UtilHandler):
    SUPPORTED_METHODS = ('GET', 'POST')

    @property
    def session(self):
        if not hasattr(self, '_session'):
            self._session = DBSession
        return self._session

    def on_finish(self):
示例#5
0
# coding=utf-8
#

import sys

sys.path.append(
    '/Users/charles/Documents/projects/myProjects/selfServiceOrder')

from app.web.webapp import run  # noqa
from app.config import CONF  # noqa

if __name__ == '__main__':
    CONF([
        '--config-file',
        '/Users/charles/Documents/projects/myProjects/selfServiceOrder/etc/dev/web.conf'
    ])
    run()
示例#6
0
# -*- coding: utf-8 -*-

import uuid
import tornado.web
import tornado.gen
from base import BaseHandler, RestHandler
from app.model import Passport
from app.service.upyun import UpyunService
from app.config import CONF
BUCKET = CONF.get('upyun', 'bucket')
DIR = CONF.get('upyun', 'dir')
DOMAIN = CONF.get('upyun', 'domain')


class ToolHandler(RestHandler):
    def permission(self):
        if not self.current_user:
            self.finish({'code': -1, 'msg': u'没有权限'})
            return

    def send_sign(self):
        name = self.get_argument('name', '')
        dir = self.get_argument('dir', '')
        result = UpyunService().sign(name, dir)
        p = dict(
            Authorization=result[0],
            p=result[1],
        )
        self.finish({'code': 0, 'data': p})
示例#7
0
                    self.session.query(Sms).filter_by(id=s.id).update(
                        {
                            'status': Sms.STATUS_COMPLETE,
                            'last': now
                        },
                        synchronize_session=False)
                else:
                    self.session.query(Sms).filter_by(id=s.id).update(
                        {'last': now}, synchronize_session=False)

                self.session.commit()

    def run(self):
        logger.info('turn')
        self.session.commit()
        self.session.query('1').all()
        try:
            self.fail()
            self.do()
        except:
            logger.error('ERROR', exc_info=True)
        IOLoop().current().add_timeout(
            IOLoop().current().time() + random.randint(5, 10), self.run)
        self.session.commit()


if __name__ == '__main__':
    Timer().run()
    if CONF.getboolean('log:filelog', 'enable'): LocalLog.start()
    IOLoop().current().start()
示例#8
0
# -*- coding: utf-8 -*-

import urllib
from base import BaseHandler
from tornado.escape import json_decode
import tornado.web
import tornado.gen
from tornado.httpclient import AsyncHTTPClient
from app.config import CONF

HOST = CONF.get('clickhouse', 'host')
PORT = CONF.get('clickhouse', 'port')
DATABASE = CONF.get('clickhouse', 'database')
TABLE = CONF.get('clickhouse', 'table')


class RealdataHandler(BaseHandler):
    @tornado.gen.engine
    def run_sql(self, sql, callback):
        url = 'http://{}:{}/'.format(HOST, PORT)
        p = {
            'database': DATABASE,
            'query': sql + ' FORMAT JSON',
        }
        url = url + '?' + urllib.urlencode(p)
        res = yield tornado.gen.Task(AsyncHTTPClient().fetch, url)
        callback(json_decode(res.body))

    @tornado.gen.coroutine
    def get(self):
        res = yield tornado.gen.Task(
示例#9
0
import hmac
from hashlib import sha1, md5
from urllib import urlencode
from email.utils import formatdate
from base import BaseService
from tornado.httpclient import HTTPClient, HTTPRequest, AsyncHTTPClient
import json

if __name__ == '__main__':
    import sys
    sys.path.insert(0, '../..')
import time
import base64
from app.config import CONF
import datetime
BUCKET = CONF.get('upyun', 'bucket')
DIR = CONF.get('upyun', 'dir')
OPERATOR = CONF.get('upyun', 'operator')
PASSWORD = CONF.get('upyun', 'password')


class UpyunService(BaseService):

    url = 'http://v1.api.upyun.com'
    base = '/' + BUCKET
    # dir = DIR
    operator = OPERATOR
    password = PASSWORD
    json = False
    raw = False
示例#10
0
# -*- coding: utf-8 -*-

from base import BaseService
from tornado.escape import json_encode
from app.model import Device
from tornado.httpclient import HTTPClient, HTTPRequest, AsyncHTTPClient

if __name__ == '__main__':
    import sys
    sys.path.insert(0, '../..')

from app.config import CONF, DBSession
APP_KEY = CONF.get('jiguang', 'appkey')
SECRET = CONF.get('jiguang', 'secret')


class JiguangService(BaseService):

    url = 'https://api.jpush.cn'
    base = '/v3'
    session = DBSession

    def gen_request(self):
        s = '{}:{}'.format(APP_KEY, SECRET)
        self.headers['Authorization'] = 'Basic {}'.format(
            s.encode('base64').strip())

        if not self.raw:
            return super(JiguangService, self).gen_request()

        url = '%s%s%s' % (self.url, self.base, self.path)
示例#11
0
# -*- coding: utf-8 -*-

from base64 import b64encode
from base import BaseService
from app.model import Device

if __name__ == '__main__':
    import sys
    sys.path.insert(0, '../..')

from app.config import CONF, DBSession
KEY = CONF.get('luosimao', 'key')


class LuoSiMao(BaseService):
    method = 'post'
    url = 'https://sms-api.luosimao.com'
    base = '/v1'
    key = KEY
    session = DBSession

    def gen_request(self):
        self.headers['Authorization'] = 'Basic ' + b64encode(
            'api:key-%s' % self.key)
        return super(LuoSiMao, self).gen_request()

    def send(self, to, data):
        self.path = '/send.json'
        self.p = {
            'mobile': to,
            'message': u'尊敬的用户:您的校验码:%s,工作人员不会索取,请勿泄露。【思科德】' % data,
示例#12
0
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    import sys
    sys.path.insert(0, '../..')

from app.config import CONF

URL = CONF.get('agent', 'url') + '/aliot'
FTPURL = CONF.get('agent', 'url')

from base import BaseService


class ALiProductService(BaseService):
    method = 'post'
    url = URL
    base = '/product'

    def create(self, name):
        self.path = '/create'
        self.p = {
            'name': name,
        }
        return self

    def update(self, productkey, productname, productdesc):
        self.path = '/update'
        self.p = {
            'productkey': productkey,
            'productname': productname,