支付寶沙箱對接(GO語言)

支付寶沙箱對接

  • 1.1 官網
  • 1.2 秘鑰生成(系統默認)
  • 1.3 秘鑰生成(軟件生成)
  • 1.4 golan 安裝 SDK
  • 1.5 GoLand 代碼
    • 1.6 前端代碼

1.1 官網


沙箱官網:

https://open.alipay.com/develop/sandbox/app

秘鑰用具下載:

https://opendocs.alipay.com/common/02kipk?pathHash=0d20b438

image-20231027214014588

1.2 秘鑰生成(系統默認)

image-20231027214829962

1.3 秘鑰生成(軟件生成)


  • 點擊生成密鑰

image-20231027214209352

  • 生成成功

image-20231027214306694

  • 自定義密鑰

image-20231027214456066****

  • 復制粘貼之前生成的公鑰并點擊保存

image-20231027214551413

  • 繼續點擊確認

image-20231027214642751

1.4 golan 安裝 SDK


go get -u github.com/smartwalle/alipay/v3

外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳

1.5 GoLand 代碼


  • app
    • utils
      • abfPay.go
package utilsimport ("fmt""github.com/smartwalle/alipay/v3""net/url"
)func ZfbPay(orderID string, totalPrice string) string {appID := "9021000131612134" // 你的appIDprivateKey := "" // 你的私鑰aliPublicKey := "" // 支付寶的公鑰var client, err = alipay.New(appID, privateKey, false)if err != nil {panic(err)}err = client.LoadAliPayPublicKey(aliPublicKey)if err != nil {panic(err)}//var p = alipay.TradeWapPay{}var p = alipay.TradePagePay{}p.NotifyURL = "http://192.168.137.188:5173/#/pages/pay-success/pay-success" //支付寶回調p.ReturnURL = "http://192.168.137.188:5173/#/pages/pay-success/pay-success" //支付后調轉頁面p.Subject = "云尚校園-訂單支付"                                                     //標題p.OutTradeNo = orderID                                                      //傳遞一個唯一單號p.TotalAmount = totalPrice                                                  //金額//p.ProductCode = "QUICK_WAP_WAY"p.ProductCode = "FAST_INSTANT_TRADE_PAY" //網頁支付var url2 *url.URLurl2, err = client.TradePagePay(p)if err != nil {fmt.Println(err)}var payURL = url2.String()println(payURL)return payURL
}
  • app
    • dto
      • Pay.go
package dtotype ShopPay struct {ByCode          string `json:"byCode"`ShopID          string `json:"id"`OrderTips       string `json:"tips"`OrderTotalPrice string `json:"totalPrice"`OrderStatus     string `json:"status"`OrderID         string `json:"order_id"`
}
  • app
    • model
      • Pay.go
package modelsimport "gorm.io/gorm"//
//  ShopPay
//  @Description: 生成訂單號
//type ShopPay struct {gorm.ModelByCode          string `gorm:"type:varchar(100)"`OrderId         string `gorm:"type:varchar(100); unique;not null"` // 訂單IDOrderStatus     string `gorm:"type:varchar(100); not null"`        // 訂單狀態OrderTips       string `gorm:"type:varchar(200); not null"`        // 訂單備注OrderTotalPrice string `gorm:"type:varchar(100); not null"`ShopID          string `gorm:"type:varchar(100); not null"`
}
  • app
    • common
      • databaseMySQL.go
package commonimport ("github.com/spf13/viper""gorm.io/driver/mysql""gorm.io/gorm"
)var DB *gorm.DBfunc InitDB() *gorm.DB {host := viper.GetString("datasource.host")port := viper.GetString("datasource.port")database := viper.GetString("datasource.database")username := viper.GetString("datasource.username")password := viper.GetString("datasource.password")charset := viper.GetString("datasource.charset")db, err := gorm.Open(mysql.Open(username+`:`+password+`@tcp(`+host+`:`+port+`)/`+database+`?charset=`+charset+`&parseTime=true&loc=Local`),&gorm.Config{})if err != nil {panic("failed to connect database, err: " + err.Error())}db.AutoMigrate(&model.ShopPay{})DB = dbreturn db
}func GetDB() *gorm.DB {return DB
}
  • app
    • config
      • application.yml
server:port: 9999datasource:diverName: mysqlhost: 127.0.0.1port: 3306database: go-appusername: rootpassword: 123456charset: utf8
  • app
    • controller
      • PayController.go
package controllerimport "github.com/gin-gonic/gin"type PayController interface {AddShopPay(ctx *gin.Context)OrderPay(ctx *gin.Context)
}
  • app
    • controller
      • pay
        • pay.go
package payimport ("github.com/gin-gonic/gin""go-app/common""go-app/controller""go-app/dto"model "go-app/models""go-app/response""go-app/utils""gorm.io/gorm""strconv"
)type PayFun interface {controller.PayController
}type payDB struct {DB *gorm.DB
}func PayFunction() PayFun {db := common.GetDB()db.AutoMigrate(model.User{})return payDB{DB: db}
}func (db payDB) AddShopPay(ctx *gin.Context) {getPayData := dto.ShopPay{}ctx.BindJSON(&getPayData)getPayData.OrderStatus = "2"getPayData.OrderID = strconv.FormatInt(utils.GetSnowflakeId(), 10)if getPayData.ByCode != "" {db.DB.Debug().Create(&getPayData)}response.Success(ctx, gin.H{"data": getPayData}, "success")
}
func (db payDB) OrderPay(ctx *gin.Context) {order := model.ShopPay{}id, _ := strconv.Atoi(ctx.Params.ByName("orderID"))db.DB.Debug().Where("order_id", id).First(&order)pay := utils.ZfbPay(order.OrderId, order.OrderTotalPrice)response.Success(ctx, gin.H{"data": pay}, "success")
}
  • app
    • router.go
package mainimport ("github.com/gin-gonic/gin"shopController "go-app/controller/shop"
)
func CollectRoute(r *gin.Engine) *gin.Engine {// 支付頁面payGroup := r.Group("api/pay/")payFun := payController.PayFunction()payGroup.POST("/AddShopPay/", payFun.AddShopPay)payGroup.POST("/orderPay/:orderID", payFun.OrderPay)return r
}
  • app
    • main.go
package mainimport ("github.com/gin-contrib/cors""github.com/gin-gonic/gin""github.com/spf13/viper""go-app/common""os"
)func main() {InitConfig()common.InitDB()r := gin.Default()config := cors.DefaultConfig()config.AllowAllOrigins = true                            //允許所有域名config.AllowMethods = []string{"GET", "POST", "OPTIONS"} //允許請求的方法config.AllowHeaders = []string{"token", "tus-resumable", "upload-length", "upload-metadata", "cache-control", "x-requested-with", "*"}r.Use(cors.New(config))// 定義路由和處理函數r = CollectRoute(r)port := viper.GetString("server.port")if port != "" {panic(r.Run(":" + port))}r.Run()
}func InitConfig() {workDir, _ := os.Getwd()viper.SetConfigName("application")viper.SetConfigType("yml")viper.AddConfigPath(workDir + "/config")err := viper.ReadInConfig()if err != nil {panic(err)}
}

1.6 前端代碼


<template><view><!-- 自定義導航欄 --><view class="box-bg" style="font-size: 36rpx;"><!-- <uni-nav-bar shadow left-icon="left" right-icon="cart" title="購物車" /> --><uni-nav-bar shadow fixed="true" left-icon="left" right-text="關閉" title="支付訂單" statusBar="true"@clickLeft="backCommitShop" @clickRight="colsePay" /></view><!-- 支付選擇模塊 --><view class="pay-main"><radio-group name=""><label><view class="pay-item"><view v-for="(item,index) in payItemIamges.data" :key="index"><view class="pay-connect"><img class="pay-item-image" :src="item.imageUrl" alt=""><view class="pay-item-text"><view class="pay-item-text-top">{{item.nameFather}}</view><view class="pay-item-text-foot">{{item.name}}</view></view><label class="pay-radio"><radio :checked="isChecked" color="#F33" /><text></text></label></view></view></view></label></radio-group></view><!-- 底部去支付模塊 --><view class="foot-pay"><view class="total-pay"><view class="total">合計:</view><view class="total">¥{{payMoney}}</view></view><view class="go-pay" @tap="goPay">去支付</view></view></view>
</template><script setup>import {onLoad,} from '@dcloudio/uni-app';import {reactive,ref} from "vue"import {orderPay} from "@/api/shop/pay.js"onLoad((e) => {// 獲取價格payMoney.value = e.price;// 獲取訂單號orderID.value = e.orderID;})// 選擇支付方式const isChecked = ref(false);const payItemIamges = reactive({data: [{nameFather: "微信支付",name: "推薦微信用戶使用",imageUrl: "http://s1jh1gxy3.hn-bkt.clouddn.com/shopCartCommit/wPay.png"},{nameFather: "支付寶支付",name: "推薦支付寶用戶使用",imageUrl: "http://s1jh1gxy3.hn-bkt.clouddn.com/shopCartCommit/zPay.png"}]})// 獲取金額const payMoney = ref(0);// 訂單ID const orderID = ref(0);// 去支付const goPay = () => {uni.navigateTo({url:"@/pages/pay-success/pay-success"})orderPay(orderID.value).then(res=>{//#ifdef APP-PLUS  plus.runtime.openURL(res.data.data, function(res){console.log(res);})//#endif // #ifdef H5window.open(res.data.data)// #endif})}const backCommitShop = () => {uni.navigateBack({delta: 1})}const colsePay = () => {uni.navigateTo({url: "../shop-commit/shop-commit"})}
</script><style lang="less" scoped>// 底部樣式.foot-pay {border-top: 2rpx solid #fcc;line-height: 100rpx;height: 100rpx;width: 100%;position: fixed;bottom: 0;left: 0;display: flex;justify-content: space-between;align-items: center;.total-pay {display: flex;flex: 1;background-color: black;color: white;padding-left: 120rpx;.total {padding: 0rpx 7rpx;}}.go-pay {padding: 0rpx 100rpx;color: white;background-color: #49BDFB;}}// 支付樣式.pay-main {margin-top: 15rpx;.pay-item {.pay-connect {display: flex;justify-content: space-between;padding: 20rpx 30rpx;border-bottom: 8rpx solid #F5F5F5;.pay-item-image {width: 100rpx;height: 100rpx;}.pay-item-text {flex: 1;padding-left: 80rpx;.pay-item-text-top {font-weight: bold;}.pay-item-text-foot {color: #636263;}}.pay-radio {padding-top: 20rpx;}}}}.box-bg {background-color: #F5F5F5;padding: 0 5px 0;}::v-deep uni-text.uni-nav-bar-text.uni-ellipsis-1 {font-size: 34rpx;font-weight: bolder;}::v-deep uni-text.uni-nav-bar-right-text {font-size: 32rpx;font-weight: bolder;}pay-item-text {flex: 1;padding-left: 80rpx;.pay-item-text-top {font-weight: bold;}.pay-item-text-foot {color: #636263;}}.pay-radio {padding-top: 20rpx;}}}}.box-bg {background-color: #F5F5F5;padding: 0 5px 0;}::v-deep uni-text.uni-nav-bar-text.uni-ellipsis-1 {font-size: 34rpx;font-weight: bolder;}::v-deep uni-text.uni-nav-bar-right-text {font-size: 32rpx;font-weight: bolder;}
</style>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/41719.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/41719.shtml
英文地址,請注明出處:http://en.pswp.cn/web/41719.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

序列化、反序列化

java 提供了一種對象序列化的機制&#xff0c;該機制中&#xff0c;一個對象可以被表示為一個字節序列&#xff0c;該字節序列包括該對象的數據、有關對象的類型的信息和存儲在對象中數據的類型。 將序列化對象寫入文件之后&#xff0c;可以從文件中讀取出來&#xff0c;并且對…

Java并發編程-ThreadLocal深入解讀及案例實戰

文章目錄 概述原理使用場景示例最佳實踐內存泄漏風險阿里開源組件TransmittableThreadLocal原理和機制使用場景如何使用注意事項ThreadLocal在分布式存儲系統edits_log案例中的實踐1. 為什么使用`ThreadLocal`?2. 實踐案例2.1 緩存日志操作2.2 線程局部的編輯日志狀態3. 注意事…

在 Spring 中編寫單元測試

單元測試是軟件開發過程中不可或缺的一部分&#xff0c;它能有效地提高代碼質量&#xff0c;確保代碼功能的正確性。在 Spring 應用中&#xff0c;JUnit 和 Mockito 是常用的單元測試工具&#xff0c;而 Spring Test 提供了豐富的測試支持。本文將介紹如何在 Spring 中使用 JUn…

并行處理百萬個文件的解析和追加

處理和解析大量文件&#xff0c;尤其是百萬級別的文件&#xff0c;是一個復雜且資源密集的任務。為實現高效并行處理&#xff0c;可以使用Python中的多種并行和并發編程工具&#xff0c;比如multiprocessing、concurrent.futures模塊以及分布式計算框架如Dask和Apache Spark。這…

物聯網時代5G通信技術分析研究一、引言

一、引言 近幾年&#xff0c;移動網絡技術跟隨互聯網的不斷發展而改革和進步&#xff0c;給平民大眾的生活也帶來新的嘗試與影響。從2G網絡的出現&#xff0c;到逐步被社會民眾所了解的3G&#xff0c;再到被熟知的且正在服務于大家的4G網絡&#xff0c;移動網絡技術的發展速度令…

jQuery Mobile 安裝指南

jQuery Mobile 安裝指南 jQuery Mobile 是一個基于 jQuery 的移動設備友好的網頁開發框架,它允許開發者創建響應式網頁和應用程序。本指南將詳細介紹如何安裝 jQuery Mobile,并確保您的開發環境準備好進行移動網頁開發。 1. 環境準備 在開始安裝 jQuery Mobile 之前,請確…

Mysql系列-Binlog主從同步

原文鏈接&#xff1a;https://zhuanlan.zhihu.com/p/669450627 一、主從同步概述 mysql主從同步&#xff0c;即MySQL Replication,可以實現將數據從一臺數據庫服務器同步到多臺數據庫服務器。MySQL數據庫自帶主 從同步功能&#xff0c;經過配置&#xff0c;可以實現基于庫、表…

B端設計:任何不顧及用戶體驗的設計,都是在裝樣子,花架子

B端設計是指面向企業客戶的設計&#xff0c;通常涉及產品、服務或系統的界面和功能設計。與C端設計不同&#xff0c;B端設計更注重實用性和專業性&#xff0c;因為它直接影響企業的效率和利益。 在B端設計中&#xff0c;用戶體驗同樣至關重要。不顧及用戶體驗的設計只是空洞的表…

數據庫之索引(二)

目錄 一、如何判斷數據庫的索引是否生效 二、如何評估索引創建的是否合理 三、索引是否越多越好 四、如何處理數據庫索引失效 五、是否所有的字段都適合創建索引 一、如何判斷數據庫的索引是否生效 可以使用EXPLAIN語句查看索引是否正在使用。 例如&#xff0c;假設已經創…

70.Bug:使用list.sort(Comparator.Comping(User::getCreateTime).reverse())空指針異常

1.出錯原因&#xff1a;在xml中沒有做字段映射 報錯語句復現&#xff1a; List<User> listnew ArrayList<>()&#xff1b; xml中進行查詢數據&#xff0c;數據存放在list中........... //排序 list.sort(Comparator.Comping(User::getCreateTime).reverse())&…

經典的layui框架,還有人用嗎?令人惋惜。

自從layui官網宣布關閉之后&#xff0c;layui框架的用戶飛速下滑&#xff0c;以至于到現在貝格前端工場承接的項目中&#xff0c;鮮有要求使用layui框架的&#xff0c;那么個框架還有人用嗎&#xff1f; 一、layui沒落是不是jquery惹的禍 layui的沒落與jQuery無關。layui框架…

Hi3861 OpenHarmony嵌入式應用入門--UDP Server

本篇使用的是lwip編寫udp服務端。需要提前準備好一個PARAM_HOTSPOT_SSID宏定義的熱點&#xff0c;并且密碼為PARAM_HOTSPOT_PSK。 修改網絡參數 在Hi3861開發板上運行上述四個測試程序之前&#xff0c;需要根據你的無線路由、Linux系統IP修改 net_params.h文件的相關代碼&…

深入理解 Docker 容器技術

一、引言 在當今的云計算和軟件開發領域&#xff0c;Docker 容器技術已經成為了一項不可或缺的工具。它極大地改變了應用程序的部署和運行方式&#xff0c;為開發者和運維人員帶來了諸多便利。 二、Docker 容器是什么&#xff1f; Docker 容器是一種輕量級、可移植、自包含的…

起底:Three.js和Cesium.js,二者異同點,好比全科和專科.

Three.js和Cesium.js是兩個常用的webGL引擎&#xff0c;很多小伙伴容易把它們搞混淆了&#xff0c;今天威斯數據來詳細介紹一下&#xff0c;他們的起源、不同點和共同點&#xff0c;閱讀后你就發現二者就像全科醫院和專科醫院的關系&#xff0c;很好識別。 一、二者的起源 Th…

性能測試相關理解---性能測試流程(二)

六、性能測試流程&#xff08;如何做性能測試&#xff1f;) 根據學習全棧測試博主的課程做的筆記 1、前期準備– 項目初期就開始&#xff0c;業務需求評審時盡量參與,對業務更深刻的認識&#xff08;確定哪些是核心業務、哪些可能存在并發請求、確定什么地方會出現瓶頸,方便后…

WebOffice在線編微軟Offfice,并以二進制流的形式打開Word文檔

在日常辦公場景中&#xff0c;我們經常會遇到這種場景&#xff1a;我們的合同管理系統的各種Word,excel,ppt數據都是以二進制數組的形式存儲在數據庫中&#xff0c;如何從數據庫中讀取二進制數據&#xff0c;以二進制數據作為參數&#xff0c;然后加載到瀏覽器的Office窗口&…

【無標題】地平線2西之絕境/Horizon Forbidden West? Complete Edition(更新:V1.3.57)

游戲介紹 與埃洛伊同行&#xff0c;在危險壯美的邊疆之地揭開種種未知的神秘威脅。此完整版可完整享受廣受好評的《地平線 西之絕境?》內容和額外內容&#xff0c;包括在主線游戲后展開的后續故事“炙炎海岸”。 重返《地平線》中遙遠未來的后末日世界&#xff0c;探索遠方的土…

Twitter群發消息API接口的功能?如何配置?

Twitter群發消息API接口怎么申請&#xff1f;如何使用API接口&#xff1f; 為了方便企業和開發者有效地與用戶互動&#xff0c;Twitter提供了各種API接口&#xff0c;其中Twitter群發消息API接口尤為重要。AokSend將詳細介紹Twitter群發消息API接口的功能及其應用場景。 Twit…

html+css+js貪吃蛇游戲

貪吃蛇游戲&#x1f579;四個按鈕控制方向&#x1f3ae; 源代碼在圖片后面 點贊??關注&#x1f64f;收藏?? 互粉必回&#x1f64f;&#x1f64f;&#x1f60d;&#x1f60d;&#x1f60d; 源代碼&#x1f4df; <!DOCTYPE html> <html lang"en"&…

15jQuery引入

【一】什么是jQuery jQuery是一個輕量級的、兼容多瀏覽器的JavaScript庫。jQuery內部封裝了原生的js代碼&#xff0c;提高編寫效率 【二】jQuery引入配置 1.● 代碼復制下來放到自己建的txt中&#xff0c;然后把他移入pycharm項目中重構成js文件(注意&#xff1a;只能在當前…