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://walker-learn.xyz/archives/4781

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

Related Posts

  • In-depth Understanding of ES6 007 [Study Notes]

    Set and Map Collections. In JS, there is an `in` operator that can determine if a property exists in an object without needing to read the object's value, returning true if it exists. However, the `in` operator also checks the object's prototype chain, so using this method is only relatively safe when the object's prototype is null. Set Collection: `let set = new Set()` `set.add(5)` `set.add("5")` `console.log(s…`

    Personal Mar 8, 2025
    1.2K00
  • Go Engineer Comprehensive Course: Protobuf Guide [Study Notes]

    Protocol Buffers Getting Started Guide 1. Introduction Protocol Buffers (protobuf for short) is a language-agnostic, platform-agnostic, extensible structured data serialization mechanism developed by Google. Compared with serialization methods such as JSON and XML, protobuf is smaller, faster, and simpler. Project homepage: https://github.com/protocolbuffers/prot…

    Personal Nov 25, 2025
    1.2K00
  • TS Everest 001 [Study Notes]

    Course Outline: Set up a TypeScript development environment. Master TypeScript's basic, union, and intersection types. Understand the purpose and usage of type assertions in detail. Master type declaration methods for functions and classes in TypeScript. Master the purpose and definition of type aliases and interfaces. Master the application scenarios of generics and apply them proficiently. Flexibly apply conditional types, mapped types, and built-in types. Create and use custom types. Understand the concepts of namespaces and modules, and how to use...

    Personal Mar 27, 2025
    1.5K00
  • Go Engineer System Course 012 [Study Notes]

    Integrate Elasticsearch in Go 1. Client Library Selection 1.1 Mainstream Go ES Clients olivere/elastic: Most comprehensive features, elegant API design, supports ES 7.x/8.x elastic/go-elasticsearch: Official client, lightweight, closer to native REST API go-elasticsearch/elasticsearch: Community-maintained offi…

    Personal Nov 25, 2025
    21000
  • Go Engineer Comprehensive Course 009 [Study Notes]

    Other features: Personal Center, Favorites, Manage shipping addresses (add, delete, modify, query), Messages. Copy inventory_srv --> userop_srv. Query and replace all inventory. Elasticsearch Deep Dive Document. 1. What is Elasticsearch. Elasticsearch is a distributed, RESTful search and analytics engine built on Apache Lucene, capable of quickly…

    Personal Nov 25, 2025
    23800
EN
简体中文 繁體中文 English
欢迎🌹 Coding never stops, keep learning! 💡💻 光临🌹