Ejemplo n.º 1
0
 def get_pay_info(self):
     # 获取支付信息
     sign = self.create_sign(self.pay_data)
     self.pay_data['sign'] = sign
     xml_data = self.dict_to_xml(self.pay_data)
     headers = {'Content-Type': 'application/xml'}
     response = Http.post(self.unified_order_url,
                          xml_data,
                          headers,
                          return_json=False)
     if response:
         wx_result = self.xml_to_dict(response)
         if wx_result.get('return_code') == 'FAIL':
             self.process_login_error(wx_result['return_msg'])
         if wx_result.get('result_code') == 'FAIL':
             self.process_login_error(wx_result['err_code'])
         else:
             prepay_id = wx_result.get('prepay_id')
             pay_sign_data = {
                 'appId': self.pay_data.get('appid'),
                 'timeStamp': str(int(time.time())),
                 'nonceStr': self.pay_data.get('nonce_str'),
                 'package': 'prepay_id={0}'.format(prepay_id),
                 'signType': 'MD5'
             }
             pay_sign = self.create_sign(pay_sign_data)
             pay_sign_data.pop('appId')
             pay_sign_data['paySign'] = pay_sign
             return pay_sign_data
     else:
         raise Exception()
Ejemplo n.º 2
0
 def search_by_isbn(self, isbn):
     """
         isbn搜索的结果可以被缓存
     """
     url = self.isbn_url.format(isbn)
     result = Http.get(url)
     self.__fill_single(result)
     return result
Ejemplo n.º 3
0
 def search_by_keyword(self, keyword, page=1):
     # 根据 keyword 请求 API
     url = self.keyword_url.format(
         keyword,
         current_app.config['PER_PAGE'],  # 从配置文件导入每页的信息条数
         self.calculate_start(page))
     result = Http.get(url)
     self.__fill_collection(result)
Ejemplo n.º 4
0
 def get(self):
     wx_result = Http.get(self.wx_login_url)
     if not wx_result:
         raise Exception()
     else:
         if 'errcode' in wx_result.keys():
             self.__process_login_error(wx_result)
         else:
             return wx_result
Ejemplo n.º 5
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     result = Http.get(url)
     # 返回result为json格式的dict
     # book = query_from_mysql(isbn)
     # if book:
     #     return book
     # else:
     #     save(result)
     self.__fill_single(result)
Ejemplo n.º 6
0
 def search_by_keyword(self, keyword, page):
     """
         keyword不缓存,意义不大
     """
     page = int(page)
     url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                   self.calculate_start(page))
     result = Http.get(url)
     self.__fill_collection(result)
     return result
Ejemplo n.º 7
0
 def search_by_isbn(self, isbn):
     """
     isbn搜索
     :param isbn:书籍isbn参数
     :return: 书籍信息对象
     """
     url = self.isbn_url.format(isbn)
     result = Http.get(url)
     # print(result)
     self.__fill_single(result)
Ejemplo n.º 8
0
 def search_by_key(self, keyword, page=1):
     """
     self 可以取到类变量,访问变量的顺序
     :param keyword:
     :param page:
     :return:
     """
     url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                   self.calculate_start(page))
     result = Http.get(url)
     self.__fill_collection(result)
Ejemplo n.º 9
0
 def search_by_isbn(self, isbn):
     """
     没有存储数据的话,如果返回回去,则是伪面向对象,
     我们应该把数据存储到对象
     定义初始化变量值,并将其返回的值赋给对象本身
     将最终数据存储到对象本身,
     但是如果存储的过多,会太具体化,影响我们通过其他途径获取数据的方式
     :param isbn:
     :return:
     """
     url = self.isbn_url.format(isbn)
     result = Http.get(url)
     self.__fill_single(result)
Ejemplo n.º 10
0
    def search_by_isbn(self, isbn):
        isbn_url = self.isbn_url.format(isbn)
        result = Http.get(isbn_url)

        # 从数据库查询是否有该书,如果没有,执行保存数据库,有的话跳过
        book = Book()
        res = Book.query.filter_by(isbn=result['isbn']).first()
        if res is None:
            book.set_attrs(result)
            db.session.add(book)
            db.session.commit()

        self.__fill_single(result)
Ejemplo n.º 11
0
 def get_close_info(self):
     sign = self.create_sign(self.pay_data)
     self.pay_data['sign'] = sign
     xml_data = self.dict_to_xml(self.pay_data)
     headers = {'Content-Type': 'application/xml'}
     response = Http.post(self.close_order_url,
                          xml_data,
                          headers,
                          return_json=False)
     if response:
         wx_result = self.xml_to_dict(response)
         if wx_result.get('return_code') == 'FAIL':
             self.process_login_error(wx_result['return_msg'])
         else:
             return wx_result
     else:
         raise Exception()
Ejemplo n.º 12
0
 def search_by_keyword(self, q, page=1):
     #key = self.keyword_url.format(q, current_app.config['PER_PAGE'], self.calculate_start(page))
     key = self.keyword_url.format(q)
     result = Http.get(key)
     self.__keyword(result)
Ejemplo n.º 13
0
 def search_by_keyword(self, keyword, page=1):
     url = self.keyword_url.format(keyword, current_app.config["PER_PAGE"],
                                   self.calculate_start(page))
     result = Http.get(url)
     self.search_by_keyword(result)
Ejemplo n.º 14
0
 def get_by_isbn(cls, isbn):
     url = cls.isbn_url.format(isbn)
     result = Http.get(url)
     return result
Ejemplo n.º 15
0
 def search_by_keyword(cls, keyword, page):
     keyword_url = cls.keyword_url.format(keyword,
                                          current_app.config['PER_PAGE'],
                                          cls.calculate_start(page))
     result = Http.get(keyword_url)
     return result
Ejemplo n.º 16
0
 def search_by_isbn(self, isbn_no: str):
     url = Book.isbn_url.format(isbn_no)
     result = Http.get(url)
     self.__single(result)
Ejemplo n.º 17
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     result = Http.get(url)
     self.__fill_single(result)
Ejemplo n.º 18
0
 def search_by_isbn(cls, isbn):
     url = cls.isbn_url.format(isbn)
     result = Http.get(url)
     # 返回result为json格式的dict
     return result
Ejemplo n.º 19
0
 def search_by_keyword(cls, keyword, page=1):
     # url = cls.isbn_url.format(keyword, cls.per_page, (page-1)*cls.per_page)
     url = cls.isbn_url.format(keyword, current_app.config['PER_PAGE'],
                               cls.calculate_start(page))
     result = Http.get(url)
     return result
Ejemplo n.º 20
0
 def search_by_keyword(self, keyword, page=1):
     # url = cls.isbn_url.format(keyword, cls.per_page, (page-1)*cls.per_page)
     url = self.isbn_url.format(keyword, current_app.config['PER_PAGE'], self.calculate_start(page))
     result = Http.get(url)
     self.__fill_collection(result)
Ejemplo n.º 21
0
 def search_by_isbn(self, q):
     isbn = self.isbn_url.format(q)
     result = Http.get(str(isbn))
     self.__isbn(result)
Ejemplo n.º 22
0
 def search_by_key(self, keyword, page):
     key_url = self.key_url.format(keyword, current_app.config['PER_PAGE'], self.calculate_start(page))
     result = Http.get(key_url)
     self.__fill_collection(result)
Ejemplo n.º 23
0
 def search_by_keyword(self, keyword, page=1):
     url = self.keyword_url.format(keyword,
                                   current_app.config.get('PER_PAGE'),
                                   self.calulate_start(page))
     result = Http.get(url)
     self.__fill_collection(result)
Ejemplo n.º 24
0
 def search_by_keyword(self, keyword, page=1):
     url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                   self.__get_start_page(page))
     result = Http.get(url)
     self.__fill_collection(result)
Ejemplo n.º 25
0
 def get_by_keyword(cls, keyword):
     url = cls.keyword_url.format(keyword)
     result = Http.get(url)
     return result
Ejemplo n.º 26
0
 def search_by_keyword(self, keyword: str, page: int = 1):
     url = self.keyword_url.format(keyword,
                                   current_app.config.get('PER_PAGE'),
                                   Book.__get_start(page))
     result = Http.get(url)
     self.__collections(result)
Ejemplo n.º 27
0
 def search_by_isbn(cls, isbn):
     isbn_url = cls.isbn_url.format(isbn)
     result = Http.get(isbn_url)
     return result