Beispiel #1
0
def message_api(telephone, verification_code):
    """
    调用阿里云短信服务
    """
    # 服务器的AccessKeyId和AccessKeySecret
    client = AcsClient(SEND_SMS_CONFIG['AccessKeyId'],
                       SEND_SMS_CONFIG['AccessKeySecret'], 'cn-hangzhou')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', str(telephone))
    request.add_query_param('SignName', "三螺旋大数据")
    request.add_query_param('TemplateCode', SEND_SMS_CONFIG['TemplateCode'])
    request.add_query_param('TemplateParam',
                            "{'code':" + verification_code + "}")

    response = client.do_action_with_exception(request)
    return_message = eval(str(response, encoding='utf-8'))
    # print(return_message)
    return return_message["Code"] is "OK"
Beispiel #2
0
def notify():
    """
    发送警告信息
    """
    client = AcsClient(current_app.config['SMS_ACCESS_KEY_ID'],
                       current_app.config['SMS_ACCESS_SECRET'])
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', g.data.get("phone"))
    request.add_query_param('SignName', "OUOStore")
    request.add_query_param('TemplateCode', "SMS_187951460")
    request.add_query_param('TemplateParam',
                            "{\"code\":%d}" % int(g.data.get("code")))

    response = client.do_action_with_exception(request)
    print(str(response, encoding='utf-8'))
    try:
        return jsonify(trueReturn(None))
    except:
        traceback.print_exc()
        return jsonify(falseReturn(None, 'data error'))
Beispiel #3
0
def send_message(tel, code=None):
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.request import CommonRequest
    client = AcsClient('LTAI4GCfPeu4kevrKwSMynRY',
                       'GHSBMqJdQu7n89I9Mn1puKia9UVv43', 'cn-hangzhou')

    if code is None:
        code = random.randint(100001, 999999)

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', str(tel))
    request.add_query_param('SignName', "狂野男孩聊天室")
    request.add_query_param('TemplateCode', "SMS_186947418")
    request.add_query_param('TemplateParam', str({'code': code}))

    response = client.do_action_with_exception(request)
    # response = client.do_action(request)
    response = eval(response)
    if response['Code'] != "OK":
        raise TypeError(response)

    return code
def BeginSend(PhoneNum, AccessKeyId, AccessSecret, SignName, TemplateCode):
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.request import CommonRequest
    client = AcsClient(AccessKeyId, AccessSecret, 'cn-hangzhou')
    # 生成验证码
    authCode = str(random.randint(1000, 9999))
    dict = {'code': authCode}
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')
    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', PhoneNum)
    request.add_query_param('SignName', SignName)
    request.add_query_param('TemplateCode', TemplateCode)
    # request.add_query_param('TemplateParam', "{'code':'5648'}")
    request.add_query_param('TemplateParam', str(dict))
    # 请求
    response = client.do_action(request)
    cjson = json.loads(str(response, 'utf-8'))
    cjson['authCode'] = authCode
    print(json.dumps(cjson))
    return cjson
Beispiel #5
0
 def get(self):
     username = self.args['username']
     page_index = self.args['currentPage']
     page_size = self.args['page_size']
     request = DescribeInstancesRequest()
     request.set_accept_format('json')
     response = self.client.do_action_with_exception(request)
     response = json.loads(str(response, encoding='utf-8'))
     response["PageNumber"] = page_index
     response["PageSize"] = page_size
     # 排除数据库中未写入的host数据
     instances_not_in_db = [
         instance_id for instance_id in response["Instances"]["Instance"]
         if not Host.query.filter_by(
             ali_instance_id=instance_id['InstanceId']).first()
     ]
     response["Instances"]["Instance"] = instances_not_in_db
     return response
Beispiel #6
0
def msg_send(code):
    client.publish('newWrLog/whitenoise1', code)
    msgclient = AcsClient('LTAI4FsrQPUPENTfptHcCTuX',
                          'adtlupVoqOCwemfuAiwAFGIOfelPTR', 'cn-hangzhou')
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')
    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', "15072976763")
    request.add_query_param('SignName', "智能食品仓库管家")
    request.add_query_param('TemplateCode', "SMS_175536303")
    request.add_query_param('TemplateParam', "{\"code\":\"" + code + "\"}")
    response = msgclient.do_action(request)
    print(str(response, encoding='utf-8'))
Beispiel #7
0
def send_smg():
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendBatchSms')
    data = request.get_json(silent=True)
    tel = [tel.phone_number for tel in data]
    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumberJson', json.dumps(phone_number))
    request.add_query_param('SignNameJson', json.dumps(["龙鱼游戏", "龙鱼游戏"]))
    request.add_query_param('TemplateCode', "SMS_175050744")
    request.add_query_param('TemplateParamJson',
                            json.dumps([{
                                "code": "8080"
                            }] * len(tel)))
    response = client.do_action(request)
    return response, 200, {
        'Authorization': request.headers['Authorization'],
        'code': 0
    }
Beispiel #8
0
def handle_message(event):

    message = event.message.text
    message_bytes = message.encode('utf-8')
    base64_bytes = base64.b64encode(message_bytes)
    base64_message = base64_bytes.decode('utf-8')

    request = PubRequest()
    request.set_accept_format('json')
    request.set_TopicFullName(ALICLOUD_IOT_TOPIC)
    request.set_MessageContent(base64_message)
    request.set_ProductKey(ALICLOUD_IOT_PRODUCTKEY)
    request.set_Qos("0")
    client.do_action_with_exception(request)
    #result = str(response)
    if message == "1":
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text="電気をつけました"))
    elif message == "0":
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text="電気を消しました"))
    else:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=message))
Beispiel #9
0
def shen_qing_jie_tiao(info):
    shu_ju = info.split(
        "."
    )  #{jk_name: "132", jk_money: "123", back_date: "123", jk_reason: "123"}
    # #print(info)
    forme_data = {
        "jk_name": shu_ju[0],
        "jk_money": shu_ju[1],
        "back_date": shu_ju[2],
        "jk_reason": shu_ju[3],
        "zhai_zhu_phone": shu_ju[4],
        "jie_kuan_ren_id": shu_ju[5]
    }
    #print(forme_data)#获取返回来的借款信息 表里面 欠款人是债主的意思
    conn = pymysql.connect(host='39.108.15.78',
                           port=3306,
                           user='******',
                           passwd='Xueyiyang',
                           db='yang_ying_jie_dai',
                           charset='utf8')
    cur = conn.cursor()
    for k in forme_data:
        if forme_data[k]:
            pass
        else:
            forme_data[k] = ""
    jk_ri_qi = datetime.date.today()
    key_excut = "insert into yong_hu_jie_tiao_tb(zhai_zhu_ren_id,jie_kuan_ren_name,jie_kuan_jing_e,jie_kuan_ri_qi,gui_huan_ri_qi,jie_kuan_yuan_yin,shi_fou_que_ren,jie_kuan_ren_id) values(%s,%s,%s,%s,%s,%s,%s,%s)" % (
        "'" + forme_data["zhai_zhu_phone"] + "'", "'" + forme_data["jk_name"] +
        "'", "'" + forme_data["jk_money"] + "'", "'" + str(jk_ri_qi) + "'",
        "'" + forme_data["back_date"] + "'", "'" + forme_data["jk_reason"] +
        "'", "'" + "NO" + "'", "'" + forme_data["jie_kuan_ren_id"] + "'")
    # #print(key_excut,"999999999999999999999999999")
    cur.execute(key_excut)
    conn.commit()
    #print("ti jiao cheng gong")
    data = json.dumps({
        "res": "借条已经成立,并且给对方发送了短信",
        "suc": "成功",
        "std": "1",
        "data": {
            "user_id": "",
            "user_info": key_excut
        }
    })
    client = AcsClient('LTAIkhQicIDwuAPU', 'TatinbuNNC4MMD9lCLBQPUs1i3WVgF',
                       'cn-hangzhou')
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers',
                            "{}".format(forme_data["zhai_zhu_phone"]))
    request.add_query_param('SignName', "友借友还")
    request.add_query_param('TemplateCode', "SMS_165414732")
    request.add_query_param(
        'TemplateParam',
        "{\"code\":\"%s\"}" % forme_data["jie_kuan_ren_id"][-4:])

    response = client.do_action(request)
    # python2:  print(response)
    # print(str(response, encoding='utf-8'))
    return data