Example #1
0
    def post_data(self):
        """
        标准post 可以自己实现 ,需要定义 self.create_request_data()
        """
        data = GooglePayRedis.get_access_token()
        if data:
            access_token_data = json.loads(data)
        ctime = int(time.time())
        if data and access_token_data.get("exptime") >= ctime:
            access_token = access_token_data.get("access_token")

        else:
            params = self.create_request_data()
            params_encode = urllib.urlencode(params)
            data = RequestApi.post_body_request(
                self.path, params_encode,
                {"Content-Type": "application/x-www-form-urlencoded"},
                self.host)
            data = json.loads(data)
            access_token = data.get("access_token")
            expires_in = data.get("expires_in")
            GooglePayRedis.set_access_token(access_token,
                                            ctime + expires_in - 60)

        purchase_check_host = "www.googleapis.com"
        purchase_check_path = "/androidpublisher/v2/applications/"+self.package_name\
                             +"/purchases/products/"+self.product_id+"/tokens/"\
                             + self.purchase_token

        data = RequestApi.get_json(purchase_check_path,
                                   {"access_token": access_token}, {},
                                   purchase_check_host)

        return data
Example #2
0
    def delete_user_tag(self, user, tags):
        """
        tag_dict:
                 0,
                 1
        """

        
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/remove_tag?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body=  [
                    {
                        "To_Account": user.sid,
                        "Tags": tag_dict
                    },
                ]

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        if result.get("ActionStatus") == "ok":
            return True , None
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #3
0
    def push_all(self, message):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/push?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                    "MsgRandom": int(time.time()),
                    "MsgBody": [
                        {
                            "MsgType": "TIMTextElem",
                            "MsgContent": {
                                "Text": message,
                            }
                        }
                    ]
              }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        if result.get("ActionStatus") == "ok":
            return True , result.get("TaskId")
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #4
0
    def send_system_message(cls, user_id, desc):
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")
        random_int = int(time.mktime(datetime.datetime.now().timetuple()))
        uri = "/v4/openim/sendmsg?usersig=%s&identifier=admin&sdkappid=%s&random=%s&contenttype=json" % (sig, app_id,random_int)
        message = {"messageTypeKey": 500, "content": '<html><h1>你已满足认证条件,快去进行视频聊天赚钱吧</h1><img src="https://hdlive-10048692.image.myqcloud.com/activity_1493192518">beauty</img></html>'}

        body = {
            # "From_Account": user.sid,
            # "To_Account": to_list,
            "SyncOtherMachine": 2,
            "From_Account": "1",
            "To_Account": user_id,
            "MsgRandom": random_int,
            "MsgBody": [
                {

                    "MsgType": "TIMCustomElem",
                    "MsgContent": {
                        "Data": json.dumps(message),
                        "Desc": user_id,
                    }
                }
            ]
        }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        if result.get("ActionStatus") == "OK":
            return True, result
        else:
            return False, "%s:%s" % (result.get("ErrorInfo", ""), result.get("ErrorCode", ""))
Example #5
0
    def portrait_set(self, user):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/profile/portrait_set?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                 "From_Account":user.sid,
                 "ProfileItem":
                 [
                     {
                        "Tag":"Tag_Profile_IM_Nick", 
                        "Value":user.nickname,
                     }
                 ]
              }
        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        #print data

        if result.get("ActionStatus") == "ok":
            return True , None
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #6
0
    def friend_delete(self, user, to_user):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/sns/friend_delete?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                    "From_Account":user.sid,
                    "To_Account":[to_user.sid],
                    "DeleteType":"Delete_Type_Both",
              }


        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        print data

        if result.get("ActionStatus") == "ok":
            return True , None
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #7
0
    def friend_import(self, user, to_user,platform):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")


        uri = "/v4/sns/friend_import?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                    "From_Account":user.sid,
                    "AddFriendItem":
                    [
                        {
                            "To_Account":to_user.sid, 
                            "Remark":to_user.nickname,
                            "RemarkTime": int(time.time()),
                            "GroupName":[u"好友"], 
                            "AddSource":"AddSource_Type_%s" % platform,
                            "AddWording":u"请加我为好友,我是你好友",
                            "AddTime":int(time.time()),
                        },
                    ]
              }
        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        #print data

        if result.get("ActionStatus") == "ok":
            return True , None
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #8
0
    def change_friends_allow_type(self, user):
        """
        更改好友申请权限(默认为自动添加,改为需要认证)
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/profile/portrait_set?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig, app_id)

        body = {
            "From_Account": user.sid,
            "ProfileItem":
            [
                {
                    "Tag":"Tag_Profile_IM_AllowType",
                    "Value":"AllowType_Type_NeedConfirm"
                }
            ]
        }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        if result.get("ActionStatus") == "OK":
            return True, result
        else:
            return False, "%s:%s" % (result.get("ErrorInfo", ""), result.get("ErrorCode", ""))
Example #9
0
def multiaccount_import():
    app_id = settings.QCLOUD_LIVE_SDK_APP_ID
    sig = gen_signature(app_id, "admin")
    random_int = int(time.mktime(datetime.datetime.now().timetuple()))
    #https: // console.tim.qq.com / v4 / im_open_login_svc / account_import?usersig = xxx & identifier = admin & sdkappid = 88888888 & random = 99999999 & contenttype = json

    uri = "/v4/im_open_login_svc/multiaccount_import?usersig=%s&identifier=admin&sdkappid=%s&random=%s&contenttype=json" % (
        sig, app_id, random_int)

    accounts = []
    for i in range(3100050, 3100081):
        accounts.append(str(i))

    body = {"Accounts": accounts}

    body = json.dumps(body)
    data = RequestApi.post_body_request(uri,
                                        body,
                                        headers={},
                                        host='console.tim.qq.com')
    result = json.loads(data)
    print result
    if result.get("ActionStatus") == "OK":
        return True, result
    else:
        return False, "%s:%s" % (result.get("ErrorInfo",
                                            ""), result.get("ErrorCode", ""))
Example #10
0
    def message_in_bottle(self, user, to_list, random_int, desc):
        """
        发送漂流瓶消息
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/batchsendmsg?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig, app_id)

        num = 0
        #todo 改成异步
        while len(to_list)>num:

            body = {
                # "From_Account": user.sid,
                # "To_Account": to_list,
                "SyncOtherMachine": 2,
                "From_Account": user.sid,
                "To_Account": to_list[num:num+500],
                "MsgRandom": random_int,
                "MsgBody": [
                    {
                        "MsgType": "TIMTextElem",
                        "MsgContent": {
                            "Text": desc,
                        }
                    },
                    {
                        "MsgType": "TIMTextElem",
                        "MsgContent": {
                            "Text": user.sid,
                        }
                    },
                ],
                "OfflinePushInfo": {
                    "PushFlag": 1,
                }
            }

            body = json.dumps(body)
            data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
            result = json.loads(data)
            num += 500

        if result.get("ActionStatus") == "OK":
            return True, result
        else:
            return False, "%s:%s" % (result.get("ErrorInfo", ""), result.get("ErrorCode", ""))
Example #11
0
    def voice_in_bottle(self, user, to_list, random_int, listen_url, url_duration):
        """
        发送漂流瓶语音
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/batchsendmsg?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig, app_id)

        message = {"messageTypeKey": 301, "listen_url": listen_url, "seconds": url_duration, }
        message_body = json.dumps(message)

        body = {
            # "From_Account": user.sid,
            # "To_Account": to_list,
            "SyncOtherMachine": 2,
            "From_Account": user.sid,
            "To_Account": ["43"],
            "MsgRandom": random_int,
            "MsgBody": [
                {
                    "MsgType": "TIMTextElem",
                    "MsgContent": {
                        "Text": listen_url,
                    }
                },
                {
                    "MsgType": "TIMCustomElem",
                    "MsgContent": {
                        "Data": message_body,
                        "Desc": user.sid,
                        # "Ext": "url"
                    }
                },
            ],
            "OfflinePushInfo": {
                "PushFlag": 1,
            },
        }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        if result.get("ActionStatus") == "OK":
            return True, result
        else:
            return False, "%s:%s" % (result.get("ErrorInfo", ""), result.get("ErrorCode", ""))
Example #12
0
    def openim_dirty_words_get(self, wordarr):
        """
        查询自定义脏字
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim_dirty_words/get?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body=  {}


        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        return result
Example #13
0
    def portrait_get(self, user):
        """
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/profile/portrait_get?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                "To_Account":[user.sid], 
                "TagList":
                [
                    "Tag_Profile_IM_Nick"    
                ]
              }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        return result
Example #14
0
    def query_push_status(self, task_id):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/get_push_report?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body=  [
                    {
                        "TaskId": task_id,
                    }
                ]

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        return result
Example #15
0
    def check_online(self, user):
        """
        检查用户是否在线
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/querystate?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig, app_id)

        body = {
                    "To_Account": user
               }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        if result.get("ActionStatus") == "OK":
            return True, result.get("QueryResult")
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #16
0
    def user_tag_list(self, user):
        """
        tag_dict:
                 0,
                 1
        """

        
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/openim/get_tag?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body=  {
                        "To_Account": [ user.sid],
                }
                

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        return result
Example #17
0
    def black_list_delete(self, user, to_user):
        """
        删除黑名单
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/sns/black_list_delete?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
            "From_Account": user.sid,
            "To_Account": [to_user.sid]
        }

        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        print data

        if result.get("ActionStatus").upper() == "OK":
            return True, None
        else:
            return False, "%s:%s" % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #18
0
    def friend_list(self, user):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/sns/friend_get_all?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                    "From_Account":user.sid,
                    "StartIndex":0,
                    "TagList":
                    [
                        "Tag_Profile_IM_Nick"
                    ],
                    "GetCount":100
              }
        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)

        return result
Example #19
0
    def account_import(self, user):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/im_open_login_svc/account_import?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body = {
                "Identifier":user.sid,
                "Nick":user.nickname,
                "FaceUrl": user.user_logo,
              }
        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        #print data

        if result.get("ActionStatus") == "ok":
            return True , None
        else:
            return False, "%s:%s"  % (result.get("ErrorInfo",""),result.get("ErrorCode",""))
Example #20
0
    def friend_check(self, user, to_user,platform):
        """
        这里用户注册的时候需要同步用户信息,
        用户更新的时候需要同步用户信息,到腾讯云
        """
        app_id = settings.QCLOUD_LIVE_SDK_APP_ID
        sig = gen_signature(app_id, "admin")

        uri = "/v4/sns/friend_check?usersig=%s&identifier=admin&sdkappid=%s&contenttype=json" % (sig,app_id)
        body= {
                    "From_Account":user.sid,
                    "To_Account":[to_user.sid],
                    "DeleteType":"CheckResult_Type_BothWay",
              }
        body = json.dumps(body)
        data = RequestApi.post_body_request(uri, body, headers={}, host='console.tim.qq.com')
        result = json.loads(data)
        #print data

        for i in result.get('CheckItem',[]):
            if i.get("Relation") == "CheckResult_Type_BothWay":
                return True

        return False