main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "kernel"
  6. "time"
  7. )
  8. func init() {
  9. account:= kernel.Client{}
  10. account.Protocol = "https"
  11. account.GatewayHost = "openapi.alipay.com"
  12. account.AppId = "<-- 请填写您的AppId,例如:2019022663440152 -->"
  13. account.SignType = "RSA2"
  14. account.AlipayPublicKey = "<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->"
  15. account.MerchantPrivateKey = "<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->"
  16. kernel.InitClient(account)
  17. }
  18. func main() {
  19. result, _ := kernel.Execute("alipay.trade.create", nil, getBizParams(time.Now().Format("2006-01-02 15:04:05")))
  20. fmt.Println(result)
  21. }
  22. func getBizParams(outTradeNo string) map[string]string {
  23. bizParams := map[string]string{
  24. "subject": "phone6 16G",
  25. "out_trade_no": outTradeNo,
  26. "total_amount": "0.10",
  27. "buyer_id": "2088002656718920",
  28. "extend_params": getHuabeiParams(),
  29. }
  30. return bizParams
  31. }
  32. func getHuabeiParams() string {
  33. extendParams := map[string]string{
  34. "hb_fq_num": "3",
  35. "hb_fq_seller_percent": "3",
  36. }
  37. byt, _ := json.Marshal(extendParams)
  38. return string(byt)
  39. }