程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Order payment and comments - daily fresh e-commerce website project series blog based on Django framework (XV)

編輯:Python

List of articles

  1. Demand analysis —— be based on Django Framework daily fresh e-commerce website project series blog ( One )
  2. Website framework construction —— be based on Django Framework daily fresh e-commerce website project series blog ( Two )
  3. User registration module —— be based on Django Framework daily fresh e-commerce website project series blog ( 3、 ... and )
  4. User login module —— be based on Django Framework daily fresh e-commerce website project series blog ( Four )
  5. User center module —— be based on Django Framework daily fresh e-commerce website project series blog ( 5、 ... and )
  6. Distributed FastDFS file system —— be based on Django Framework daily fresh e-commerce website project series blog ( 6、 ... and )
  7. home page —— be based on Django Framework daily fresh e-commerce website project series blog ( 7、 ... and )
  8. Details page —— be based on Django Framework daily fresh e-commerce website project series blog ( 8、 ... and )
  9. List of pp. —— be based on Django Framework daily fresh e-commerce website project series blog ( Nine )
  10. Commodity search —— be based on Django Framework daily fresh e-commerce website project series blog ( Ten )
  11. Shopping cart record add —— be based on Django Framework daily fresh e-commerce website project series blog ( 11、 ... and )
  12. Shopping cart record update —— be based on Django Framework daily fresh e-commerce website project series blog ( Twelve )
  13. Order generation —— be based on Django Framework daily fresh e-commerce website project series blog ( 13、 ... and )
  14. Order concurrent processing —— be based on Django Framework daily fresh e-commerce website project series blog ( fourteen )
  15. Order payment and comments —— be based on Django Framework daily fresh e-commerce website project series blog ( 15、 ... and )
  16. To be updated ……

Project resources download

  1. Daily fresh e-commerce website project source code Github Address ( can Fork can Clone)
  2. Daily fresh e-commerce website project source code Gitee Address ( can Fork can Clone)
  3. Daily fresh e-commerce website project source code compressed package download ( Use it directly )
  4. Package and download all the tools required for the daily fresh e-commerce website project (nginx、libfastcommon、fastdfs-nginx、fastdfs)
  5. Daily fresh e-commerce website project MySql Database files ( Direct import MySql database )
  6. Django1.8 Official documents ( Chinese version )

List of articles

  • List of articles
  • Project resources download
  • Preface
  • One 、 User center order page
  • Two 、 Flow chart of website docking with Alipay
  • 3、 ... and 、 The website connects with Alipay payment
  • Four 、 Order payment function module
  • 5、 ... and 、 Get payment results
  • 6、 ... and 、 The order comment function is implemented
  • summary


Preface

   Today will be the last long and rare article on the implementation of module functions , That is, the website commodity order payment and comment function module have to be realized . This includes the preparation of the order page, the docking with Alipay payment and its entire process, as well as the realization of its functions , It's a lot of content , Don't talk much , Start today's study now !


One 、 User center order page

  1. First, in the shopping cart payment interface html Medium Js Add the following code :
  2. Because it automatically jumps to the user order interface after clicking , So you need to configure the route
  3. Then write the corresponding view function
    ①: First, get the user's order information

    ②: Then traverse to get the information of the order items

    ③: Then page

    ④: Then organize the context

    ⑤: Finally, use the template , Pass in the parameter
  4. Then write our html Templates
    ①: First modify here base.html and base_user_center.html Templates


    ②: And then use user_center_order.html Receive data and display data
  5. Effect display

Two 、 Flow chart of website docking with Alipay

3、 ... and 、 The website connects with Alipay payment

  1. Because we are a personal project , So we can only use the sandbox in the development service to test our payment business
  2. As we are paying for computer websites , So you can refer to the official documents
  3. Quick access steps of computer website payment
  4. Icon Django The website connects with Alipay platform
  5. Start configuring public and private keys
    ①: Enter sandbox environment

    ②: Then download the key generator and install


    ③: Click generate key

    ④: Generate public and private keys

    ⑤: Application of public key

    ⑥: Generate application public key and Alipay public key , And save

Four 、 Order payment function module

  1. install python-alipay-sdk
pip install python-alipay-sdk --upgrade
# about python2, Please install 2.0 The following versions : pip install python-alipay-sdk==1.1
  1. Generate key file ( Use OpenSSL Software , Need to download )
openssl
OpenSSL> genrsa -out app_private_key.pem 2048 # Private key 
OpenSSL> rsa -in app_private_key.pem -pubout -out app_public_key.pem # Export public key 
OpenSSL> exit
  1. The public key downloaded from Alipay is a string , You need to add marker bits at the beginning and end of the text
-----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----
  1. In order to use it properly , The format of the certificate is as follows :
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAptkXVjUkA21vOW+h7FrW
68sooGwRqZCT3c8zcP7WLwwvKzwpiU5l+oX7yMoEes9qa7TCZd6YySxoYAdi1u9R
6Bi5YOeWCKGfh5ijbaWU9vH5k/qgWzCkWMSu0ZDyV0rMnQHigrnlEWGNOdMxglTJ
EeuiIGLi7i/3loFUjwCfXq8bkEcylTMMGiXGh88qevG0SbVA8RBNO37tHsRtSD/M
U1hIcjTDMH5+yiLGKVx1OjdOlX0nrjTivM0i9uQn0NZaBBVT7SVT/CykmpSLxX5P
tTJ+I56uRUpeQyRd+vaeTdqrmTFmpG3Nd0nUJV0wWespzOBgg+fYG9Sd7yoEb8g2
JwIDAQAB
-----END PUBLIC KEY-----
  1. And then save it
  2. Application of public key
  3. Save Alipay public key
  4. Copy private key
  5. Payment background view
    ①: Write order payment function

    ②: Verify that the user is logged in

    ③: Receiving parameters

    ④: Calibration parameters

    ⑤: initialization

    ⑥: Call payment interface

    ⑦: Back to answer
  6. To configure url
  7. Write the front end Js Code to get the order id, Pass parameters , Visit the appropriate address
  8. Effect display


5、 ... and 、 Get payment results

  1. To write Js Code , After jumping to the payment success interface, it will automatically jump to the user's personal center interface
  2. To configure url
  3. Write the corresponding view function , View the results of order payment
    ①: So let's define the function

    ②: Determine whether the user is logged in

    ③: Receiving parameters

    ④: Calibration parameters

    ⑤: Business processing : Use python sdk Call Alipay's payment interface

    ⑥: Call Alipay's transaction query interface , And return the corresponding data
  4. According to the received data , stay Js Determine whether the payment is successful in the code , If the payment is successful , Automatically refresh the user's personal center page , Show payment success , The item list shows the items to be evaluated
  5. Effect display

6、 ... and 、 The order comment function is implemented

  1. First, guide users to comment on the successful payment page in the user's personal center , Set jump href, The user's paid goods id Pass in
  2. Configure corresponding url
  3. Write the corresponding view function
  4. First of all, we click to comment is a get request , Take the paid goods of the user id To visit comment Interface , It's a get request
  5. Then we need to complete the click comment function of the order in this function
    ①: First get the user , Then verify the parameters

    ②: Then get the information of the order goods

    ③: Finally, use the template , Pass product information to comments html Interface , display information

    ④: Receive information in the corresponding comment interface , Display information

    ⑤: Effect display
  6. When we make comments , It's a post request , Let's get users first , Then verify the parameters
  7. Then we complete the comment function in this function
    ①: First, get the number of comments

    ②: Then get the comment information

    ③: Pass the corresponding parameters after success
  8. Finally, modify the product details page html, First, add labels to product information and comments , And accept the data
  9. Then write the corresponding Js Code , Click to display product details and comments respectively
  10. Effect display

summary

   This blog post is a little long , But it's also the last article in this series that goes to , The next two articles are relatively simple , Including website deployment and project summary , I personally think that if there is no such requirement or no server, there is no need to deploy the website , Otherwise, you need to use virtual machines . But if there is a server or you are willing to instigate, you can refer to my other blogs , It can also be deployed , And it can realize Internet access ( The next blog will give you a link ), The wonderful content will be announced in the next blog !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved