mopybird 1 سال پیش
والد
کامیت
4f6e02d3c8
2فایلهای تغییر یافته به همراه129 افزوده شده و 1 حذف شده
  1. 127 1
      library/alipay/__init__.py
  2. 2 0
      library/alipay/exceptions.py

+ 127 - 1
library/alipay/__init__.py

@@ -186,7 +186,7 @@ class BaseAliPay(object):
 
 
         return sorted(data.items())
         return sorted(data.items())
 
 
-    def build_body(self, method, append_auth_token = False, **query):
+    def build_body(self, method, append_auth_token = False, notify_url = None, **query):
         data = {
         data = {
             "app_id": self._appid,
             "app_id": self._appid,
             "method": method,
             "method": method,
@@ -199,6 +199,9 @@ class BaseAliPay(object):
         if append_auth_token:
         if append_auth_token:
             data["app_auth_token"] = self.app_auth_token
             data["app_auth_token"] = self.app_auth_token
 
 
+        if notify_url:
+            data['notify_url'] = notify_url
+
         data.update(query)
         data.update(query)
 
 
         if self.aes_encrypt_key and 'biz_content' in data:
         if self.aes_encrypt_key and 'biz_content' in data:
@@ -836,6 +839,128 @@ class BaseAliPay(object):
             raw_string, "ant_merchant_expand_indirect_image_upload_response"
             raw_string, "ant_merchant_expand_indirect_image_upload_response"
         )
         )
 
 
+    def api_alipay_user_agreement_page_sign(
+            self, personal_product_code, sign_scene, access_params,
+            product_code, external_agreement_no, third_party_type, external_logon_id,
+            sign_validity_period = None, notify_url = None):
+
+        biz_content = {
+            "personal_product_code": personal_product_code,
+            "sign_scene": sign_scene,
+            "access_params": access_params,
+            "product_code": product_code,
+            "external_agreement_no": external_agreement_no,
+            "third_party_type": third_party_type
+        }
+
+        if external_logon_id:
+            biz_content.update({
+                "external_logon_id": external_logon_id
+            })
+
+        if sign_validity_period:
+            biz_content.update({
+                'sign_validity_period': sign_validity_period
+            })
+
+        data = self.build_body("alipay.user.agreement.page.sign", notify_url = notify_url, biz_content = biz_content)
+        return self._gateway + "?" + self.sign_data(data)
+
+    def api_alipay_user_agreement_query(
+            self, personal_product_code, sign_scene, product_code, external_agreement_no):
+
+        biz_content = {
+            "personal_product_code": personal_product_code,
+            "sign_scene": sign_scene,
+            "product_code": product_code,
+            "external_agreement_no": external_agreement_no
+        }
+
+        data = self.build_body("alipay.user.agreement.query", biz_content = biz_content)
+        url = self._gateway + "?" + self.sign_data(data)
+
+        raw_string = self._request(method = "get", url = url)
+        return self._verify_and_return_sync_response(
+            raw_string, "alipay_user_agreement_query_response"
+        )
+
+    def api_alipay_user_agreement_unsign(
+            self, personal_product_code, sign_scene, external_agreement_no):
+
+        biz_content = {
+            "personal_product_code": personal_product_code,
+            "sign_scene": sign_scene,
+            "external_agreement_no": external_agreement_no
+        }
+
+        data = self.build_body("alipay.user.agreement.unsign", biz_content = biz_content)
+        url = self._gateway + "?" + self.sign_data(data)
+
+        raw_string = self._request(method = "get", url = url)
+        return self._verify_and_return_sync_response(
+            raw_string, "alipay_user_agreement_unsign_response"
+        )
+
+    def api_alipay_fund_accountbook_create(self, merchant_user_id, merchant_user_type, scene_code, ext_info):
+        biz_content = {
+            "merchant_user_id": merchant_user_id,
+            "merchant_user_type": merchant_user_type,
+            "scene_code": scene_code,
+            "ext_info": ext_info
+        }
+
+        data = self.build_body("alipay.fund.accountbook.create", biz_content = biz_content)
+        url = self._gateway + "?" + self.sign_data(data)
+
+        raw_string = self._request(method = "get", url = url)
+        return self._verify_and_return_sync_response(
+            raw_string, "alipay_fund_accountbook_create_response"
+        )
+
+    def api_alipay_fund_accountbook_query(self, account_book_id, scene_code, ext_info):
+        biz_content = {
+            "account_book_id": account_book_id,
+            "scene_code": scene_code,
+            "ext_info": ext_info
+        }
+
+        data = self.build_body("alipay.fund.accountbook.query", biz_content = biz_content)
+        url = self._gateway + "?" + self.sign_data(data)
+
+        raw_string = self._request(method = "get", url = url)
+        return self._verify_and_return_sync_response(
+            raw_string, "alipay_fund_accountbook_query_response"
+        )
+
+    def api_alipay_fund_trans_page_pay(self, agreement_no, account_book_id, out_biz_no, trans_amount, time_expire, remark = u'转账', order_title = u'代发专项充值'):
+        biz_content = {
+            'out_biz_no': out_biz_no,
+            'trans_amount': trans_amount,
+            'product_code': 'FUND_ACCOUNT_BOOK',
+            'biz_scene': 'SATF_DEPOSIT',
+            'remark': remark,
+            'order_title': order_title,
+            'time_expire':time_expire,
+            'payee_info': {
+                'identity_type': 'ACCOUNT_BOOK_ID',
+                'identity': account_book_id,
+                'ext_info': json.dumps({
+                    'agreement_no':agreement_no
+                })
+            }
+        }
+
+        data = self.build_body("alipay.fund.trans.page.pay", biz_content = biz_content)
+        url = self._gateway + "?" + self.sign_data(data)
+        return url
+
+        # raw_string = self._request(method = "get", url = url)
+        # return raw_string
+        # return self._verify_and_return_sync_response(
+        #     raw_string, "alipay_fund_accountbook_query_response"
+        # )
+
+
 class AliPay(BaseAliPay):
 class AliPay(BaseAliPay):
     def __init__(self, appid,
     def __init__(self, appid,
                  app_private_key_string,
                  app_private_key_string,
@@ -1051,3 +1176,4 @@ class ISVAliPay(BaseAliPay):
         return self._verify_and_return_sync_response(
         return self._verify_and_return_sync_response(
             raw_string, "alipay_open_auth_token_app_query_response"
             raw_string, "alipay_open_auth_token_app_query_response"
         )
         )
+

+ 2 - 0
library/alipay/exceptions.py

@@ -57,8 +57,10 @@ class AliValidationError(AliException):
 class AliPayGatewayException(AliException):
 class AliPayGatewayException(AliException):
     pass
     pass
 
 
+
 class AliPayServiceException(AliException):
 class AliPayServiceException(AliException):
     pass
     pass
 
 
+
 class AliPayNetworkException(AliException):
 class AliPayNetworkException(AliException):
     pass
     pass