Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
panjinjie authored and panjinjie committed Oct 17, 2018
1 parent 97ca819 commit 3581e42
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 11 deletions.
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/panjjo/ppp

require (
github.com/agtorre/gocolorize v1.0.0 // indirect
github.com/howeyc/fsnotify v0.9.0 // indirect
github.com/panjjo/go-config v0.0.0-20161221052437-9f16f7c197bc
github.com/panjjo/log4go v0.0.0-20161217074253-5bde1464d311
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/agtorre/gocolorize v1.0.0 h1:TvGQd+fAqWQlDjQxSKe//Y6RaxK+RHpEU9X/zPmHW50=
github.com/agtorre/gocolorize v1.0.0/go.mod h1:cH6imfTkHVBRJhSOeSeEZhB4zqEYSq0sXuIyehgZMIY=
github.com/howeyc/fsnotify v0.9.0 h1:0gtV5JmOKH4A8SsFxG2BczSeXWWPvcMT0euZt5gDAxY=
github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA=
github.com/panjjo/go-config v0.0.0-20161221052437-9f16f7c197bc h1:+c7r2Qp8B0g0Q3H3XsulW7bt4p8kXrbznG3k6thFXIw=
github.com/panjjo/go-config v0.0.0-20161221052437-9f16f7c197bc/go.mod h1:/9K3P1JgkWR8NiAYgcFfOrCUywXprC1h+BmIsZY+wo0=
github.com/panjjo/log4go v0.0.0-20161217074253-5bde1464d311 h1:JHhBHReQwr5E+WOCZb+8ManfZqGfNIcKnDxjxtZRBsQ=
github.com/panjjo/log4go v0.0.0-20161217074253-5bde1464d311/go.mod h1:z6qSWwFYCtf8U5VX9Qudejb/32IZXAIyevxuxx3SZTU=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
7 changes: 4 additions & 3 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ const (
)

const (
PAYTYPE_ALIPAY = "alipay"
PAYTYPE_WXPAY = "wxpay"
PAYTYPE_PPP = "ppp"
PAYTYPE_ALIPAY = "alipay"
PAYTYPE_WXPAY = "wxpay"
PAYTYPE_WXPAYSG = "wxpaysg"
PAYTYPE_PPP = "ppp"
)

type rsys struct {
Expand Down
37 changes: 36 additions & 1 deletion rpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
} else {
log.Fatal(err)
}

log.Println("a")
//wxpay
config.Mod = ppp.PAYTYPE_WXPAY
if ok, err := config.GetBool("status"); ok {
Expand All @@ -51,6 +51,17 @@ func main() {
} else {
log.Fatal(err)
}
log.Println("a")

//wxpaysg
config.Mod = ppp.PAYTYPE_WXPAYSG
if ok, err := config.GetBool("status"); ok {
initWXPaySG()
wxsg := new(ppp.WXPaySG)
rpc.Register(wxsg)
} else {
log.Fatal(err)
}

//db
config.Mod = "database"
Expand Down Expand Up @@ -114,3 +125,27 @@ func initWXPay() {
}
wx.Init()
}

func initWXPaySG() {
wx := ppp.WXPaySGInit{
ConfigPath: *configPath,
}
var err error
if wx.AppId, err = config.GetString("appid"); err != nil {
log.Fatal("Init Error:Not Found wxpay:appid")
}
if wx.Url, err = config.GetString("url"); err != nil {
log.Fatal("Init Error:Not Found wxpay:url")
}
if wx.MchId, err = config.GetString("mchid"); err != nil {
log.Fatal("Init Error:Not Found wxpay:mchid")
}
if wx.ApiKey, err = config.GetString("key"); err != nil {
log.Fatal("Init Error:Not Found wxpay:apikey")
}
if wx.NotifyUrl, err = config.GetString("notify"); err != nil {
log.Fatal("Init Error:Not Found wxpay:notify_url")
}
wx.Init()
}

39 changes: 39 additions & 0 deletions sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var aliPayPrivateKey *rsa.PrivateKey //应用私钥
var aliPayPublicKey *rsa.PublicKey //支付宝公钥
var wxPaySecretKey string //微信支付
var wxPayCertTlsConfig *tls.Config //微信支付证书tls
var wxPaySGSecretKey string //微信支付
var wxPaySGCertTlsConfig *tls.Config //微信支付证书tls

//WXPay使用私钥做验签
//用于同步接口请求
Expand All @@ -31,6 +33,15 @@ func WXPaySigner(data map[string]string) (signer string) {
return strings.ToUpper(makeMd5(message))
}

//WXPay使用私钥做验签
//用于同步接口请求
//异步回调接口的验证也是用此方法
func WXPaySGSigner(data map[string]string) (signer string) {
message := mapSortAndJoin(data, "=", "&", true)
message += "&key=" + wxPaySGSecretKey
return strings.ToUpper(makeMd5(message))
}

//AliPay使用私钥做验签
//用于同步接口请求
func AliPaySigner(data map[string]string) (signer []byte) {
Expand Down Expand Up @@ -99,3 +110,31 @@ func loadWXPayCertKey(path string) {
}

}

//加载微信支付相关证书信息
func loadWXPaySGCertKey(path string) {
b, err := ioutil.ReadFile(filepath.Join(path, "cert/wxpay_single/cert.p12"))
if err != nil {
log.Fatal("Load WXPaySG Cert Error:", err)
}

blocks, err := pkcs12.ToPEM(b, wxPaySGMchId)
if err != nil {
log.Fatal("Load WXPaySG Cert Error:", err)
}

var pemData []byte
for _, b := range blocks {
pemData = append(pemData, pem.EncodeToMemory(b)...)
}

cert, err := tls.X509KeyPair(pemData, pemData)
if err != nil {
log.Fatal("Load WXPaySG Cert Error:", err)
}

wxPaySGCertTlsConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}

}
9 changes: 2 additions & 7 deletions wxpay.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,6 @@ type wxWapPayResult struct {
CodeUrl string `xml:"code_url"`
}

var (
wxPayTypeJS = "JSAPI"
wxPayTypeH5 = "MWEB"
)

//网页支付
//子商户模式
func (W *WXPay) WapPayParams(request *WapPayRequest, resp *Response) error {
Expand Down Expand Up @@ -656,7 +651,7 @@ func (W *WXPay) WapPayParams(request *WapPayRequest, resp *Response) error {
"h5_info": map[string]interface{}{"type": "Wap", "wap_url": request.Scene.Url, "wap_name": request.Scene.Name},
})),
}
if params.TradeType == wxPayTypeJS {
if params.TradeType == JSPAYPARAMS {
if params.OpenId == "" && params.SubOpenId == "" {
resp.Code = SysErrParams
resp.SourceData = fmt.Sprintf("trade type:%s,openid or sub_openid must have one", params.TradeType)
Expand Down Expand Up @@ -694,7 +689,7 @@ func (W *WXPay) WapPayParams(request *WapPayRequest, resp *Response) error {
//成功返回
tmpresult := wxWapPayResult{}
xml.Unmarshal(result.([]byte), &tmpresult)
if params.TradeType == wxPayTypeJS {
if params.TradeType == JSPAYPARAMS {
jsParams := map[string]string{
"appId": wxPayAppId,
"timeStamp": fmt.Sprintf("%d", getNowSec()),
Expand Down
Loading

0 comments on commit 3581e42

Please sign in to comment.