smartwalle/alipay

可否更新一下readme

Closed this issue · 5 comments

fanux commented
可否更新一下readme

是有什么问题?

fanux commented

我看到实际代码中的接口和文档中描述的不太一样。

func New(appId, aliPublicKey, privateKey string, isProduction bool) (client *AliPay) {

1.0.2版本,也并没有一些Load证书的接口。

昨天试了没太使用成功不太清楚原因:

func New() *Alipay {
	a := &Alipay{
		AppPrivateKey:      os.Getenv("AppPrivareKey"),
		AppCertPublicKey:    os.Getenv("AppCertPublicKey"),
		AlipayRootCert:      os.Getenv("AlipayRootCert"),
		AlipayCertPublicKey: os.Getenv("AlipayCertPublicKey"),
		AppId:               os.Getenv("AppId"),
	}
	a.AppPrivateKey = "MIIEpAIBAAKCAQE...==" // 这俩用官方工具生成的应用私钥和应用公钥证书
	a.AppCertPublicKey = "4yHBj69p9z9ss9aWkLRfvxc7wIDAQAB..."
	client := alipay.New(a.AppId,a.AppCertPublicKey,a.AppPrivateKey,true)
	a.Client = client
	fmt.Println(*a)
	return a
}

// 给支付宝账户付款
func (a *Alipay) PayTo(account string, amount int) error {
	p := alipay.AliPayFundTransToAccountTransfer{}
	p.OutBizNo = fmt.Sprintf("%s-%s-%d",time.Now().String(),account,amount)
	p.PayeeType = "ALIPAY_LOGONID"
	p.PayeeAccount = account
	p.Amount = strconv.Itoa(amount)
	rsp, err := a.Client.FundTransToAccountTransfer(p)
	if err != nil {
		return fmt.Errorf("pay for %s failed %s, resp : %v",account,err,rsp)
	}
	if !rsp.IsSuccess(){
		return fmt.Errorf("pay for %s not success %s",account,err)
	}
	time.Sleep(time.Second * 30)
	return nil
}

最后提示:
crypto/rsa: verification error

不知道啥情况

fanux commented

我切到v3版本一试

fanux commented

{40002 Invalid Arguments isv.invalid-signature 验签出错,建议检查签名字符串或签名私钥与应用公钥是否匹配,网关生成的验签字符串为:alipay_root_cert_sn=687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6&app_id=2021001146671059&biz_content={"out_biz_no":"2020-03-23 14:40:38.808917 +0800 CST m=+0.002386010-15805691422-1","payee_type":"ALIPAY_LOGONID","payee_account":"15805691422","amount":"1","payer_show_name":"","payee_real_name":"","remark":""}&charset=utf-8&format=JSON&method=alipay.fund.trans.toaccount.transfer&sign_type=RSA2&timestamp=2020-03-23 14:40:38&version=1.0 } NgK8FSu0SWYD4ZEMcebI8eHVaz2X9BviUWmWfwQpPsT+VzETvIc7JSpmrcdPWHdXPZRgkkBtBFOmPlqrKnxCMTIpLweyxuKFSRut5LSqfTYDj/B5WsaWXJZMDV+6MdIkFhtm3FOhGMSflx3NSLp24nlJAhhdcuppNnggEeeeoyd+G8vWovaPB+qKEcGT+T6JAPf3rSzz0In11z8aKFELrfpfu6KV2No6IxNuevDETZyvgnN+IcR/JUVreOoVgXL7T/tYul8mWjAzoWT2m35DgNSVLJV25RXErmT+c9u6MsIUv2Z0O/fxWreU2m3nNPxGizWH41QWUTu9qGf2l2Jfag==}

切到v3提示这个,对了几遍私钥应该是对的

fanux commented

image

彻底重新试了下,可以了,把老的全删了。 大家注意除了私钥其它的都要在这个页面下载下来