Python输出返回在Api密钥sms脚本中不起作用

2024-03-28 23:55:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个python脚本,它从API键返回帐户信息 网址:pvasms.com pvasms.com上的教程:http://smspva.com/new_theme_api.html我在github上已经找到了两个脚本:https://github.com/ooojustin/smspva/blob/master/smspva/smsrequest.pyhttps://github.com/alihossein/smspva/blob/master/SmsPva.py

我已经尝试了这两种方法,当我运行时,我用Api键替换了值:0错误,但它没有返回任何内容

    import requests


class SmsPva:
    def __init__(self):
        self._url = 'http://smspva.com/priemnik.php'
        self._api_key = 'myapikey'
        self._method_type = 'get'
        self._query_string = {}

    def get_number(self, id=1, country='ru', service='opt29'):
        """
        Request for receiving a phone number for a certain service
        :return:
        """
        self._query_string = {'metod': 'get_number', 'country': country, 'service': service, 'id': id,
                              'apikey': self._api_key}
        result = self.__make_request()
        return result

    def get_sms(self, id, country='ru', service='opt29'):
        """
        Receiving a SMS for a certain service
        :return:
        """
        self._query_string = {'metod': 'get_sms', 'country': country, 'service': service, 'id': id,
                              'apikey': self._api_key}
        result = self.__make_request()
        return result

    def get_balance(self, service='opt29'):
        """
        User's balance request
        :param service:
        :return:
        """
        self._query_string = {'metod': 'get_balance', 'service': service, 'apikey': self._api_key}
        result = self.__make_request()
        return result

    def get_userinfo(self, service='opt29'):
        """
        User's balance request and karma (Your rating)
        :return:
        """
        self._query_string = {'metod': 'get_userinfo', 'service': service, 'apikey': self._api_key}
        result = self.__make_request()
        return result

    def get_count_new(self, service='opt29', country='ru'):
        """
        Request for the amount of free activations for a certain service
        :param country:
        :param service:
        :return:
        """
        self.query_string = {'metod': 'get_count_new', 'service': service, 'country': country, 'apikey': self._api_key}
        result = self.__make_request()
        return result

    def denial(self, id, country='ru', service='opt29'):
        """
        Cancel the order to number you got
        :return:
        """
        self._query_string = {'metod': 'denial', 'country': country, 'service': service, 'id': id,
                              'apikey': self._api_key}
        result = self.__make_request()
        return result

    def __make_request(self):
        """
        make request post or get , ...
        :return:
        """

        try:
            if self._method_type == 'get':
                response = requests.get(self._url, self._query_string)
            elif self._method_type == 'post':
                pass

            if response.status_code == 200:
                return response.json()
            else:
                return response

        except Exception as e:
            return e

Tags: keyselfcomapiidgetstringmake
1条回答
网友
1楼 · 发布于 2024-03-28 23:55:24

您应该首先将代码中的所有国家/地区和服务部分更改为您想要的,然后查看类中的方法(如get_number)及其下面的注释,并查看您想要使用哪一个。当您执行这两个步骤时,请将其写在代码下面(没有任何缩进)

request = SmsPva
request.get_number() # change get_number with any other methods in the class that you want
# you can do the last line over and over with other methods

然后您可以使用如下打印功能获得输出:

print(request.get_number())

最后,我建议将来学习python;)

相关问题 更多 >