Commit da55a1f2 authored by wangp's avatar wangp

卡拉卡

parent d115f679
...@@ -18,7 +18,6 @@ import ( ...@@ -18,7 +18,6 @@ import (
"system_pay/models" "system_pay/models"
"system_pay/mysql" "system_pay/mysql"
"system_pay/setting" "system_pay/setting"
"system_pay/utils"
) )
// 拉卡拉支付 // 拉卡拉支付
...@@ -65,8 +64,10 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput, ip string) (interface{}, ...@@ -65,8 +64,10 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput, ip string) (interface{},
var url string var url string
if false { //source_code 1: 微信 Native 2:微信小程序 3:微信内支付 4:h5 跳微信
//聚合收银台(微信H5+支付宝H5) //5:支付宝(web)-扫码或登录支付宝账户 6:alipay(mobile) 7:alipay(app)
if input.SourceCode==4 || input.SourceCode==6 {
//聚合收银台(微信H5、支付宝H5、微信扫码、支付宝扫码)
url = "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //聚合收银台 url = "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //聚合收银台
data["req_time"] = "20230626100000" data["req_time"] = "20230626100000"
...@@ -83,10 +84,10 @@ if false { ...@@ -83,10 +84,10 @@ if false {
data2 := make(map[string]interface{}) data2 := make(map[string]interface{})
//data2["merchant_no"] = "8222900701107M5" //data2["merchant_no"] = "8222900701107M5"
data2["merchant_no"] = "8221210701101SB" data2["merchant_no"] = "8221210701101SB"
data2["term_no"] = "29034705" //data2["term_no"] = "29034705" //不需要传?
//data2["total_amount"] = "1" //data2["total_amount"] = "1"
data2["total_amount"] = input.GoodsPrice data2["total_amount"] = input.GoodsPrice*100
//data2["out_trade_no"] = orderID //随机生成的订单号 //商户交易流水号 //data2["out_trade_no"] = orderID //随机生成的订单号 //商户交易流水号
//data2["out_trade_no"] = RandomString(32) //data2["out_trade_no"] = RandomString(32)
data2["out_order_no"] = orderID //随机生成的订单号 //商户订单号 data2["out_order_no"] = orderID //随机生成的订单号 //商户订单号
...@@ -94,8 +95,13 @@ if false { ...@@ -94,8 +95,13 @@ if false {
//data2["out_trade_no"] = input.AttachInfo //data2["out_trade_no"] = input.AttachInfo
//data2["out_order_no"] = input.AttachInfo //data2["out_order_no"] = input.AttachInfo
if input.SourceCode < 5 {
//微信
data2["counter_param"] = "{\"pay_mode\":\"WECHAT\"}"
} else {
//支付宝
data2["counter_param"] = "{\"pay_mode\":\"ALIPAY\"}" data2["counter_param"] = "{\"pay_mode\":\"ALIPAY\"}"
//data2["counter_param"] = "{\"pay_mode\":\"WECHAT\"}" }
data2["order_efficient_time"] = "20230630235959" //订单有效期 格式yyyyMMddHHmmss,最大支持下单时间+2天 data2["order_efficient_time"] = "20230630235959" //订单有效期 格式yyyyMMddHHmmss,最大支持下单时间+2天
data2["notify_url"] = input.NoticeURL //订单支付成功后商户接收订单通知的地址 http://xxx.xxx.com data2["notify_url"] = input.NoticeURL //订单支付成功后商户接收订单通知的地址 http://xxx.xxx.com
...@@ -105,8 +111,9 @@ if false { ...@@ -105,8 +111,9 @@ if false {
data["req_data"] = make(map[string]interface{}) data["req_data"] = make(map[string]interface{})
data["req_data"] = data2 data["req_data"] = data2
} else {
//聚合主扫(微信JSAPI+微信小程序) } else if input.SourceCode==2 || input.SourceCode==3 ||input.SourceCode==1 || input.SourceCode==5 {
//聚合主扫(微信JSAPI、微信小程序)
url = "https://test.wsmsd.cn/sit/api/v3/labs/trans/preorder" //聚合主扫 url = "https://test.wsmsd.cn/sit/api/v3/labs/trans/preorder" //聚合主扫
data["req_time"] = "20230626100000" data["req_time"] = "20230626100000"
...@@ -122,11 +129,14 @@ if false { ...@@ -122,11 +129,14 @@ if false {
data2 := make(map[string]interface{}) data2 := make(map[string]interface{})
//data2["merchant_no"] = "8222900701107M5" //data2["merchant_no"] = "8222900701107M5"
data2["merchant_no"] = "8221210701101SB" //data2["term_no"] = "A1062976"
data2["term_no"] = "29034705" //data2["merchant_no"] = "8221210701101SB"
data2["merchant_no"] = "8222900581201QB"
data2["term_no"] = "D0027598"
//data2["total_amount"] = "1" //data2["total_amount"] = "1"
data2["total_amount"] = input.GoodsPrice //tempMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", p.GoodsPrice*100), 64)
data2["total_amount"] = input.GoodsPrice*100
data2["out_trade_no"] = orderID //随机生成的订单号 //商户交易流水号 data2["out_trade_no"] = orderID //随机生成的订单号 //商户交易流水号
//data2["out_trade_no"] = RandomString(32) //data2["out_trade_no"] = RandomString(32)
//data2["out_order_no"] = orderID //随机生成的订单号 //商户订单号 //data2["out_order_no"] = orderID //随机生成的订单号 //商户订单号
...@@ -134,18 +144,28 @@ if false { ...@@ -134,18 +144,28 @@ if false {
//data2["out_trade_no"] = input.AttachInfo //data2["out_trade_no"] = input.AttachInfo
//data2["out_order_no"] = input.AttachInfo //data2["out_order_no"] = input.AttachInfo
//data2["counter_param"] = "{\"pay_mode\":\"ALIPAY\"}"
data2["counter_param"] = "{\"pay_mode\":\"WECHAT\"}"
data2["order_efficient_time"] = "20230630235959" //订单有效期 格式yyyyMMddHHmmss,最大支持下单时间+2天 data2["order_efficient_time"] = "20230630235959" //订单有效期 格式yyyyMMddHHmmss,最大支持下单时间+2天
data2["notify_url"] = input.NoticeURL //订单支付成功后商户接收订单通知的地址 http://xxx.xxx.com data2["notify_url"] = input.NoticeURL //订单支付成功后商户接收订单通知的地址 http://xxx.xxx.com
data2["callback_url"] = input.ReturnURL //客户端下单完成支付后返回的商户网页跳转地址 data2["callback_url"] = input.ReturnURL //客户端下单完成支付后返回的商户网页跳转地址
data2["order_info"] = "必康测试订单标题2" //订单标题,在使用收银台扫码支付时必输入,交易时送往账户端 data2["order_info"] = "必康测试订单标题2" //订单标题,在使用收银台扫码支付时必输入,交易时送往账户端
//data2["goods_mark"] = input.AttachInfo //商品信息标识 (1:含商品信息,不填默认不含商品信息) //data2["goods_mark"] = input.AttachInfo //商品信息标识 (1:含商品信息,不填默认不含商品信息)
if input.SourceCode==1 {
//微信native
data2["counter_param"] = "{\"pay_mode\":\"WECHAT\"}"
data2["account_type"] = "WECHAT" //钱包类型
data2["trans_type"] = "41" //接入方式
} else if input.SourceCode==5 {
//支付宝native
data2["counter_param"] = "{\"pay_mode\":\"ALIPAY\"}"
data2["account_type"] = "ALIPAY" //钱包类型
data2["trans_type"] = "41" //接入方式
} else {
//微信JSAPI、微信小程序
data2["counter_param"] = "{\"pay_mode\":\"WECHAT\"}"
data2["account_type"] = "WECHAT" //钱包类型 data2["account_type"] = "WECHAT" //钱包类型
data2["trans_type"] = "51" //接入方式 data2["trans_type"] = "51" //接入方式
}
//地址位置信息 //地址位置信息
data3 := make(map[string]interface{}) data3 := make(map[string]interface{})
...@@ -153,9 +173,23 @@ if false { ...@@ -153,9 +173,23 @@ if false {
data2["location_info"] = make(map[string]interface{}) data2["location_info"] = make(map[string]interface{})
data2["location_info"] = data3 data2["location_info"] = data3
//地址位置信息
data4 := make(map[string]interface{})
//data4["open_id"] = input.OpenID //此参数 支付类型是 JS API 的时候 必传
data4["sub_appid"] = "wxc3e4d1682da3053c"
data4["user_id"] = "oLvoQ5deygCMj2WrDjPVPvV1L1t8"
data2["acc_busi_fields"] = make(map[string]interface{})
data2["acc_busi_fields"] = data4
data["req_data"] = make(map[string]interface{}) data["req_data"] = make(map[string]interface{})
data["req_data"] = data2 data["req_data"] = data2
} else {
return nil, errors.New("输入参数「source_code」错误")
} }
//数据重组 - end //数据重组 - end
fmt.Println("拉卡拉输入参数") fmt.Println("拉卡拉输入参数")
fmt.Println(data) fmt.Println(data)
...@@ -180,14 +214,14 @@ if false { ...@@ -180,14 +214,14 @@ if false {
//url := "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //聚合收银台 //url := "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //聚合收银台
//调拉卡拉接口 //调拉卡拉接口
err, m_web_url, lakala_rtn := lakala_post(url, data_json) err, response, lakala_rtn := lakala_post(input.SourceCode, url, data_json)
if err != nil { if err != nil {
InsertPayBillDetailResponseBody(tx, billID, lakala_rtn) InsertPayBillDetailResponseBody(tx, billID, lakala_rtn)
return nil, err return nil, err
} }
response := make(map[string]string) //response := make(map[string]string)
response["m_web_url"] = m_web_url //response["m_web_url"] = m_web_url
// 插入下单成功后返回的参数 // 插入下单成功后返回的参数
err = InsertPayBillDetailResponseBody(tx, billID, lakala_rtn) err = InsertPayBillDetailResponseBody(tx, billID, lakala_rtn)
...@@ -200,15 +234,12 @@ if false { ...@@ -200,15 +234,12 @@ if false {
} }
func lakala_post(source_code uint8, url string, data_json []byte) (error, interface{}, interface{}) {
func lakala_post(url string, data_json []byte) (error, string, interface{}) {
authorization, err := getAuthorization(string(data_json)) authorization, err := getAuthorization(string(data_json))
if err != nil { if err != nil {
return err, "", nil return err, "", nil
} }
fmt.Println(url) fmt.Println(url)
fmt.Println(authorization) fmt.Println(authorization)
...@@ -232,19 +263,41 @@ func lakala_post(url string, data_json []byte) (error, string, interface{}) { ...@@ -232,19 +263,41 @@ func lakala_post(url string, data_json []byte) (error, string, interface{}) {
fmt.Println("拉卡拉返回值") fmt.Println("拉卡拉返回值")
fmt.Println(temp) fmt.Println(temp)
//todo //todo
if temp["code"] != "000000" { if temp["code"] != "000000" && temp["code"] != "BBS00000"{
//this.Data["json"] = utils.CheckError(errors.New("拉卡拉错误"), temp["msg"].(string)) //todo //this.Data["json"] = utils.CheckError(errors.New("拉卡拉错误"), temp["msg"].(string)) //todo
//this.ServeJSON() //this.ServeJSON()
return errors.New(temp["msg"].(string)), "", temp return errors.New(temp["msg"].(string)), "", temp
} }
//return nil, temp["resp_data"]["counter_url"] //return nil, temp["resp_data"]["counter_url"]
response := make(map[string]string)
if source_code==4 || source_code==6 || source_code==1 || source_code==5 {
//聚合收银台(微信H5、支付宝H5、微信扫码、支付宝扫码)
temp2, _ := temp["resp_data"].(map[string]interface{}) temp2, _ := temp["resp_data"].(map[string]interface{})
if temp2["counter_url"]=="" { if temp2["counter_url"]=="" {
return errors.New("拉卡拉返回值「counter_url」为空错误"), "", temp return errors.New("拉卡拉返回值「counter_url」为空错误"), "", temp
} }
response["m_web_url"] = temp2["counter_url"].(string)
} else if source_code==2 || source_code==3 {
//聚合主扫(微信JSAPI+微信小程序)
temp2, _ := temp["resp_data"].(map[string]interface{})
temp3, _ := temp2["acc_resp_fields"].(map[string]interface{})
//if temp3["counter_url"]=="" {
// return errors.New("拉卡拉返回值「counter_url」为空错误"), "", temp
//}
response["app_id"] = temp3["app_id"].(string)
response["nonce_str"] = temp3["nonce_str"].(string)
response["package"] = temp3["package"].(string)
response["pay_sign"] = temp3["pay_sign"].(string)
response["prepay_id"] = temp3["prepay_id"].(string)
response["sign_type"] = temp3["sign_type"].(string)
response["timeStamp"] = temp3["time_stamp"].(string)
} else {
return errors.New("输入参数「source_code」错误"), "", temp
}
return nil, temp2["counter_url"].(string), temp return nil, response, temp
} }
func getAuthorization(body string) (string, error) { func getAuthorization(body string) (string, error) {
...@@ -281,21 +334,22 @@ func getAuthorization(body string) (string, error) { ...@@ -281,21 +334,22 @@ func getAuthorization(body string) (string, error) {
fmt.Println("签名1:", signature) fmt.Println("签名1:", signature)
base64Sig, err := utils.RSASign([]byte(message), "./cert/OP00000003_private_key.pem") //base64Sig, err := utils.RSASign([]byte(message), "./cert/OP00000003_private_key.pem")
if err != nil { //if err != nil {
return signature, err // return signature, err
} //}
//
fmt.Println("签名2:", base64Sig) //fmt.Println("签名2:", base64Sig)
//
err = utils.RSAVerify([]byte(message), base64Sig, "./cert/OP00000003_cert.cer") //err = utils.RSAVerify([]byte(message), signature, "./cert/OP00000003_cert.cer")
if err == nil { ////err = utils.RSAVerify([]byte(message), signature, "./cert/lkl-apigw-v2.cer")
fmt.Println("验证成功!") //if err == nil {
} else { // fmt.Println("验证成功!")
fmt.Println("验证失败!") //} else {
return "", err // fmt.Println("验证失败!")
} // return "", err
return "", errors.New("wangpei签名测试中。。。。。") //}
//return "", errors.New("wangpei签名测试中。。。。。")
authorization := "LKLAPI-SHA256withRSA " + "appid=\"" + appid + "\"," + "serial_no=\"" + mchSerialNo + "\"," + "timestamp=\"" + timestamp + "\"," + "nonce_str=\"" + nonceStr + "\"," + "signature=\"" + signature + "\""; authorization := "LKLAPI-SHA256withRSA " + "appid=\"" + appid + "\"," + "serial_no=\"" + mchSerialNo + "\"," + "timestamp=\"" + timestamp + "\"," + "nonce_str=\"" + nonceStr + "\"," + "signature=\"" + signature + "\"";
...@@ -629,7 +683,7 @@ func UnifiedOrder2(input *models.PlaceAnOrderParamInput) (interface{}, error) { ...@@ -629,7 +683,7 @@ func UnifiedOrder2(input *models.PlaceAnOrderParamInput) (interface{}, error) {
//url := "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //聚合收银台 //url := "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //聚合收银台
//调拉卡拉接口 //调拉卡拉接口
err, _, _ = lakala_post(url, data_json) err, _, _ = lakala_post(input.SourceCode, url, data_json)
if err != nil { if err != nil {
//this.Data["json"] = utils.CheckError(err,"拉卡拉错误") //this.Data["json"] = utils.CheckError(err,"拉卡拉错误")
//this.ServeJSON() //this.ServeJSON()
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"hash"
"io/ioutil" "io/ioutil"
) )
...@@ -38,7 +39,6 @@ func RSASign(data []byte, filename string) (string, error) { ...@@ -38,7 +39,6 @@ func RSASign(data []byte, filename string) (string, error) {
return "", err return "", err
} }
// 3、RSA数字签名(参数是随机数、私钥对象、哈希类型、签名文件的哈希串),生成base64编码的签名字符串 // 3、RSA数字签名(参数是随机数、私钥对象、哈希类型、签名文件的哈希串),生成base64编码的签名字符串
//bytes, err := rsa.SignPKCS1v15(rand.Reader, privateKey, myhash, hashed)
bytes, err := rsa.SignPKCS1v15(rand.Reader, privateKey, myhash, hashed) bytes, err := rsa.SignPKCS1v15(rand.Reader, privateKey, myhash, hashed)
if err != nil { if err != nil {
return "", err return "", err
...@@ -84,7 +84,7 @@ func ReadParsePublicKey(filename string) (*rsa.PublicKey, error) { ...@@ -84,7 +84,7 @@ func ReadParsePublicKey(filename string) (*rsa.PublicKey, error) {
// 3、解析DER编码的公钥,生成公钥接口 // 3、解析DER编码的公钥,生成公钥接口
publicKeyInterface, err := x509.ParsePKIXPublicKey(block.Bytes) publicKeyInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil { if err != nil {
fmt.Println(222) fmt.Println(444)
return nil, err return nil, err
} }
...@@ -126,3 +126,40 @@ func ReadParsePrivaterKey(filename string) (*rsa.PrivateKey, error) { ...@@ -126,3 +126,40 @@ func ReadParsePrivaterKey(filename string) (*rsa.PrivateKey, error) {
return privateKey, nil return privateKey, nil
} }
func VerifySignCert(signData, sign, signType, aliPayPublicKeyPath string) (err error) {
var (
h hash.Hash
hashs crypto.Hash
block *pem.Block
pubKey *x509.Certificate
publicKey *rsa.PublicKey
ok bool
bytes []byte
)
if bytes, err = ioutil.ReadFile(aliPayPublicKeyPath); err != nil {
return fmt.Errorf("支付宝公钥文件读取失败: %w", err)
}
signBytes, _ := base64.StdEncoding.DecodeString(sign)
if block, _ = pem.Decode(bytes); block == nil {
return errors.New("支付宝公钥Decode错误")
}
if pubKey, err = x509.ParseCertificate(block.Bytes); err != nil {
return fmt.Errorf("x509.ParseCertificate:%w", err)
}
if publicKey, ok = pubKey.PublicKey.(*rsa.PublicKey); !ok {
return errors.New("支付宝公钥转换错误")
}
switch signType {
case "RSA":
hashs = crypto.SHA1
case "RSA2":
hashs = crypto.SHA256
default:
hashs = crypto.SHA256
}
h = hashs.New()
h.Write([]byte(signData))
return rsa.VerifyPKCS1v15(publicKey, hashs, h.Sum(nil), signBytes)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment