django framework - Basic - Alipay research _20191205

Alipay pay study

 

Alipay profile:

  • In order page of our user-centric, but saw under the previous state to be paid, we can click on to pay for pay,
  • We use Alipay, now look at Alipay,
  • https://open.alipay.com/platform/home.htm, this is Alipay open platform,
  • We scan code landed in,
  • Then to the Developer Center, click on the Network & mobile applications,
  • Paid access, the access time required to create an application, and then give you a appid, which is a unique identifier, and now we do not have the qualification,
  • How to do? Developer Center has a research and development services, there is a sandbox, which is a simulation of the real environment of Alipay, which is a development simulation environment, so you can develop a program, and
  • In addition you have to butt Alipay, then also need to look Alipay developer documentation, https: //docs.open.alipay.com/270, this is the computer's site to pay,
  • There is a document used in the process, you click to buy, will jump to a two-dimensional code page, after the user logs in payment, then jump back,
  • How access to this Alipay platform?
  • The first step: the need to create before docking application, then you will get a appID, and then select the computer site to pay, submitted for review, approval and you can use it,
  • The second step is to configure the keys, get a public key,
  • django site and Alipay platform, but also a way to network requests, a request to address pay treasure platform, by request of communication,
  • A need to pass parameters, this process requires a transfer request before encryption, which is related to the public and private keys,
  • The private key for encryption, public key to decrypt,
  • django website issued when Alipay platform needs through their own private key to encrypt data, then Alipay public key to decrypt, so they need to tell their public Alipay,
  • Alipay django back to the time of the message, we need to use private key encryption Alipay issued the site, then the site needs a public key to decrypt Alipay,
  • Need to make a private and public key configuration,
  • In the sandbox, set up your own public key, you can also view the public Alipay,
  • The third step is to build and configure the development environment,
  • Alipay provides several interfaces,
  • 1, alipay.trade.page.pay unified under a single acquirer and payment page interface, multi-solution after Alipay to generate payment page, you need to call this interface,
  • 2, alipay.trade.refund unified interface to receive a single transaction refund,
  • 3, alipay.trade.fastpay.refund.query unified query interface acquiring transaction refund
  • 4, alipay.trade.query unified query interface to close the transaction, then the user needs to look at the pay-line success has not paid, look at this,
  • 5, alipay.trade.close unified single transaction to close down the interface
  • 6, alipay.data.dataservice.bill.downloadurl.query query statements Download
  • There are interface documentation, you can see how to use this interface,
  • Address a formal request to address the environment is: https: //openapi.alipay.com/gateway.do
  • Address sandbox environment: https: //openapi.alipaydev.com/gateway.do
  • Whether you are doing, you are the same address, according to different parameters, it will call a different interface,
  • No matter what interface you adjust common parameters are the same, https: //docs.open.alipay.com/api_1/alipay.trade.page.pay/, and there are common parameters.
  • This parameter is written, is the need to be passed,
  • The method is to determine which interface calls,
  • biz_content, other non-public parameters are placed inside this parameter,
  • ###
  • The allocation of time also need to download the sdk, let you use more convenient, but this does not provide the python, which is a third party, python language, and use this interface to call Alipay,
  • When passing a signature needs to be done, how the signature?
  • 1, filtering and sorting, the first step is to obtain the signature of all the parameters, the remaining parameters, sorting, use of ASC code to generate a string, the string is a string to be signed,
  • The signature string, assign parameters to sign the request, send this to Ali,

Website docking Alipay flow chart

  • django site user clicks to pay,
  • Then the address to access a django site, such as the address is a orderpay, an address must have a corresponding background processing function, I want to know the payment,
  • Then go to the site Alipay request interface, generate a payment page, this time needs to pass a few parameters to Alipay, order id, the total amount of orders, order the title, these three parameters are required, there are two parameters not mandatory: redirect_uri, notify_url, eventually will return a response, it returns a payment page address,
  • After get the address of the payment page, you need to use the customer, so that the user's browser to open this page, then the user can log Alipay, paid a scan code, scan code page payment password would not matter, the rest is and payment of the treasure relations,
  • After the payment as long as the user, will soon redirect_uri visit our website, pass parameters to inform you of the results of user pay, which is synchronous access,
  • notify_url, asynchronous access notify_url, which is asynchronous, likely some time, to tell you the results of user pay, these two are the same functions are paid to tell you the results, but a synchronous, asynchronous, real to asynchronous prevail, because it may not allow synchronization,
  • Now our website is 127.0.0.1, Alipay is not accessible, to pay ip Bao access, you need a public network, no ip public network, how to obtain payment of the results of it, though Alipay can not access our site, but our site access to Alipay,
  • There is an interface, alipay.trade.query unified query interface to close the transaction, then the user needs to look at the pay-line success has not paid, look at this, we can get the result of payment through this interface, our own access is the Alipay payment to query results the Alipay payment will be returned to you the results, which is in the public network ip case, there is a public network ip, Alipay will automatically send you,

 

Orders Payment Code:

  • Click on the order list page, click to pay, using post request to pass parameters django website,
  • We need to pass parameters to the Alipay, we want to use a sdk, so do not pass our own parameters, and
  • Install this package, https: //github.com/fzlee/alipay/blob/master/README.zh-hans.md
  • Uninstall a package: pip uninstall pycrypto
  • Then install: pip install python-alipay-sdk --upgrade
  • After installing, you have this package, you can use it,
  • ########
  • To find out the sandbox environment Alipay,
  • Alipay point into the open platform website, https: //open.alipay.com/
  • Click "Open Platform - Developer Center - sandbox environment." Into the sandbox environment page, the system has automatically created as an application you can see the information in the application configuration information.
  • II. Generate a key file
  • 1. Use OpenSSL
  • openssl
  • 2. Generate a private key
  • genrsa -out app_private_key.pem 2048
  • 3. Generate the public key
  • rsa -in app_private_key.pem -pubout -out app_public_key.pem
  • 4. Exit OpenSSL
  • exit
  • ###########
  • Have their own public and private keys, the next step is to configure, Alipay sandbox environment, set their own public, public treasure will pay Alipay repeatedly,
  • The public Alipay is decrypted after we received Alipay content,
  • So we take this public Alipay to save our project there,
  • We apply the following in order, the Alipay public key and a private key that we are put under this folder, 
  • This configuration play,
  • ##################
  • how to use?
  • Pay for a click when the front-end ajax + post request,
  • Need to pass parameters: order_id,
  • Check the back-end orders, there are several query, order number put, this is the user's Alipay payment is to be paid by the state, can be found is an effective order,
  • The next step there is no problem to start the call interface Alipay,
  • 1, initialization
  • 2, transfer interfaces,
  • 3, returns a response, here's how pay_url = 'https://openapi.alipaydev.com/gateway.do?' + Order_string
  • 报错:    raise ValueError("RSA key format is not supported")
  • The time parameter to access Alipay: app_private_key_string -----> app_private_key_path
  • 报错:    raise ValueError("Not a valid PEM pre boundary")
  • Turned out to be my mark before and would like to thank the bars on both sides only five, I wrote seven, ----- END RSA PRIVATE KEY ----- Note that this must be marked on both sides and if five, not 5 will report this error,
  • Now pass,
  • Log in now sandbox environment, view sandbox account, buyers account password

Orders to pay - get paid results:

  • Because we are not a public network environment, it can not be returned to us Alipay payment results,
  • So we own to query result of the transaction,
  • After obtaining the results of the transaction Alipay, giving the user a result that payment of the success, or failure,
  • The user's browser to visit our website and see if the payment is successful,
  • When the user's browser to access our address,
  • How design? ?
  • We guide the user to pay after page,
  • Check the payment status, payment succeeded,
  • Pop successful payment, then refresh the page, to get rid of order status inside the database,

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/andy0816/p/11987820.html