Go Engineer Systematic Course 008 [Study Notes]

Orders and Shopping Cart
First, copy the service code framework of 'srv' from the inventory service, then find and replace the corresponding name (order_srv).

Fundamentals of Encryption Technology
Symmetric Encryption
Principle:
Uses the same key for encryption and decryption.
Like a single key that can both lock and unlock a door.
Fast encryption speed, suitable for large data transfers.
Use cases:
Local file encryption
Database content encryption
Content encryption during large data transfers
Fast communication between internal systems...

Orders and Shopping Cart

First, copy the srv service code framework from the inventory service, then find and replace the corresponding name (order_srv)

Basics of Encryption Technology

Symmetric Encryption

Principle:

  • Uses the same key for encryption and decryption
  • Like a single key that can both lock and unlock a door
  • Fast encryption speed, suitable for large data transfers

Use Cases:

  • Local file encryption
  • Database content encryption
  • Content encryption for large data transfers
  • Fast communication between internal systems

Pros and Cons:

  • ✅ Fast speed, high efficiency
  • ❌ Difficult key distribution, easily intercepted

Asymmetric Encryption

Principle:

  • Uses a pair of keys: public key and private key
  • Content encrypted with the public key can only be decrypted with the private key
  • Content signed with the private key can be verified with the public key
  • Like an email address (public key) and password (private key)

Use Cases:

  • Digital signature for identity verification
  • Secure transmission of symmetric encryption keys
  • HTTPS certificate verification
  • Blockchain transaction signing

Pros and Cons:

  • ✅ High security, secure key distribution
  • ❌ Slow speed, not suitable for large amounts of data

Detailed Analysis of Alipay Payment Process

Payment Flowchart

graph TD
    A[用户浏览器] -->|1. 下订单| B[慕学生鲜商户系统]
    B -->|2. 返回支付URL| A
    A -->|3. 跳转支付宝支付| C[支付宝支付平台]
    B -->|发起支付请求| C

    subgraph "商户端密钥管理"
        D[商户私钥<br/>自己留着]
        E[商户公钥<br/>给支付宝]
    end

    subgraph "支付宝端密钥管理"
        F[支付宝私钥<br/>严格保密]
        G[支付宝公钥<br/>给商户]
    end

    subgraph "安全验证机制"
        H[数字签名验证]
        I[请求可信度检查]
        J[通知真实性验证]
    end

    B -.->|使用私钥签名| D
    C -.->|使用公钥验证| E
    C -.->|使用私钥签名| F
    B -.->|使用公钥验证| G

    C -->|4. 支付结果通知| B

    style A fill:#e1f5fe
    style B fill:#f3e5f5
    style C fill:#e8f5e8
    style D fill:#ffebee
    style E fill:#fff3e0
    style F fill:#ffebee
    style G fill:#fff3e0
    style H fill:#f1f8e9
    style I fill:#f1f8e9
    style J fill:#f1f8e9

System Architecture and Participants

Three Core Roles:

  • Browser: User-side, responsible for user interaction
  • Muxueshengxian (Merchant System): E-commerce platform's backend service
  • Alipay: Third-party payment platform

Key Management System (Core of Asymmetric Encryption)

Merchant-side Key Management

  • Private Key (Secret Key - Keep to yourself):
  • Strictly confidential to the merchant, never disclosed
  • Used to digitally sign requests sent to Alipay
  • Proves that the request indeed originated from the merchant
  • Public Key (Public Key - Give to Alipay):
  • Provided to the Alipay platform
  • Alipay uses it to verify the merchant's request signature
  • Ensures the authenticity and integrity of the request

Alipay-side Key Management

  • Private Key (Secret Key):
  • Strictly confidential to Alipay
  • Used to digitally sign payment notifications
  • Proves that the notification indeed originated from official Alipay
  • Public Key (Public Key - For yourself):
  • Provided to the merchant system
  • The merchant uses it to verify Alipay's notification signature
  • Ensures the authenticity of the payment result notification

Detailed Payment Process Steps

Step 1: User Places Order

  • User browses products in the browser
  • Selects products and submits the order
  • The browser sends an order request to the merchant system

Step 2: Generate Payment Request (Key Security Step)

Merchant System Processing:

  1. Receives user order information
  2. Constructs payment parameters (order number, amount, product information, etc.)
  3. Digitally signs the payment request using the merchant's private key
  4. Sends the signed request to Alipay

Alipay Verification:

  1. Receives the merchant's payment request
  2. Verifies the request signature using the merchant's public key
  3. Checks "whether this request is trustworthy"
  4. After successful verification, generates a payment URL
  5. Returns the payment URL to the merchant system

Security Mechanism Explanation:

  • Digital signature ensures the request comes from a legitimate merchant
  • Prevents malicious third parties from forging payment requests
  • Ensures that the request data has not been tampered with during transmission

Step 3: User Pays

  • The merchant system returns the payment URL to the browser
  • The browser automatically redirects to the Alipay payment page
  • The user completes the payment operation on the Alipay page (enters password, selects payment method, etc.)

Step 4: Payment Result Notification (Key Security Step)

Alipay Processing:

  1. Processes user payment operation
  2. Generates a payment result notification
  3. Digitally signs the notification using Alipay's private key
  4. Sends the signed notification to the merchant system

Merchant System Verification:

  1. Receives Alipay's payment notification
  2. Verifies the notification signature using Alipay's public key
  3. Confirms the notification is from official Alipay
  4. Verifies payment result and order information
  5. Updates order status, completes the transaction

Security Mechanism Explanation:

  • Digital signature ensures the notification is from official Alipay
  • Prevents malicious third parties from forging successful payment notifications
  • Ensures the authenticity and integrity of payment result data

How Digital Signatures Work

The Essence of Digital Signatures:

  • Uses a private key to encrypt data, generating a "signature"
  • Uses the corresponding public key to verify the signature, confirming data source and integrity
  • Like a handwritten signature in reality, but more secure and unforgeable

Application in the Payment Process:

  1. Merchant Signature: Merchant signs with private key → Alipay verifies with merchant's public key
  2. Alipay Signature: Alipay signs with private key → Merchant verifies with Alipay's public key

Security Protection Mechanisms

Anti-forgery Attacks:

  • Cannot generate a valid signature without the private key
  • Public key can only verify, not forge signatures

Anti-tampering Attacks:

  • If data is modified, signature verification will fail
  • Ensures data integrity during transmission

Anti-replay Attacks:

  • Usually used in conjunction with timestamps and nonces
  • Prevents malicious repeated submission of the same payment request

Applications of Encryption Technology

  • Symmetric Encryption: Used for fast encrypted transmission of large amounts of payment data
  • Asymmetric Encryption: Used for digital signatures and identity verification
  • Public Key Verification: Ensures the authenticity of both communicating parties and data integrity

Alipay Developer Platform

Environment Configuration

Sandbox Environment (Testing)

  • Use Alipay sandbox environment for testing
  • Configure sandbox app ID and keys
  • Set callback notification URL

Production Environment

  • Apply for and get approval for a formal application
  • Configure production environment keys
  • Set HTTPS callback URL

Integration Notes

  1. Key Management
  2. Properly store the application private key, do not disclose it
  3. Regularly rotate keys
  4. Use environment variables to store sensitive information
  5. Communication Security
  6. All API calls must use HTTPS
  7. Verify the authenticity of Alipay's public key
  8. Encrypt sensitive data during transmission
  9. Data Validation
  10. Verify the signature of payment notifications
  11. Check order amount and status
  12. Prevent duplicate processing of notifications

Public and private keys for the sandbox environment

主题测试文章,只做测试使用。发布者:Walker,转转请注明出处:https://www.walker-learn.xyz/archives/4781

(0)
Walker的头像Walker
上一篇 Nov 25, 2025 09:00
下一篇 Nov 25, 2025 06:00

Related Posts

  • Go Engineer Comprehensive Course: protoc-gen-validate Study Notes

    protoc-gen-validate: Introduction and Usage Guide ✅ What is protoc-gen-validate? protoc-gen-validate (PGV for short) is a Protocol Buffers plugin used to add validation logic for struct fields in generated Go code. It automatically generates validation code for each field by adding validation rules in .proto files, saving you the trouble of manually...

    Personal Nov 25, 2025
    1.4K00
  • In-depth Understanding of ES6 003 [Study Notes]

    Function parameter default values, as well as some details about the `arguments` object, how to use expressions as parameters, and the temporal dead zone for parameters. Previously, setting default values always relied on expressions containing the logical OR operator. When the preceding value was false, the latter value would always be returned. However, this became problematic if we passed 0 as an argument, requiring type verification. For example, `function makeRequest(url,timeout,callback){ timeout = t...`

    Personal Mar 8, 2025
    1.3K00
  • Waving to the world, embracing infinite possibilities 🌍✨

    Standing higher, seeing further. Life is like a series of tall buildings; we constantly climb upwards, not to show off the height, but to see a broader landscape. The two girls in the picture stand atop the city, with outstretched arms, as if embracing the boundless possibilities of the world. This is not merely a journey overlooking the city, but rather, a tribute to freedom and dreams. Brave Exploration, Breaking Boundaries. Everyone's life is an adventure; we are born free, and thus should explore unknown landscapes and experience more stories. Perhaps there will be challenges along the way, but it is precisely those moments of ascent...

    Personal Feb 26, 2025
    1.4K00
  • Go Engineer System Course 004 [Study Notes]

    Requirements Analysis Backend Management System Product Management Product List Product Categories Brand Management Brand Categories Order Management Order List User Information Management User List User Addresses User Messages Carousel Management E-commerce System Login Page Homepage Product Search Product Category Navigation Carousel Display Recommended Products Display Product Details Page Product Image Display Product Description Product Specification Selection Add to Cart Shopping Cart Product List Quantity Adjustment Delete Product Checkout Function User Center Order Center My...

    Nov 25, 2025
    28600
  • Node: In-depth Yet Easy to Understand (Shengsi Garden Education) 002 [Study Notes]

    Node's package management and loading mechanisms: npm search xxx, npm view xxx, npm install xxx. Node.js file system operation APIs: Node.js's `fs` module provides synchronous (Sync) and callback/Promise-based asynchronous APIs for operating on local files and directories. Commonly used capabilities in daily development include reading, writing, appending, deleting, traversing directories, listening for changes, and so on. The following examples are based on C...

    Personal Nov 24, 2025
    31800
EN
简体中文 繁體中文 English