支付宝对接授权及加好友

Posted hmycheryl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了支付宝对接授权及加好友相关的知识,希望对你有一定的参考价值。

授权:

首先需要去支付宝开发者中心注册一个网页应用,注册时需要注意应用名称的命名规范,很容易就审核不通过,授权的回调地址必须是https的,并且页面里必须要调用getAuthCode,否则授权时就会报 系统异常,请联系商家。REDIRECT_URI_ILLEAGAL

调用授权api:

ap.getAuthCode(
  {
     appId: ‘‘,
     scopes: [auth_user],
     showErrorTip: false
  },
  function (res) {
     // dosomething
  }
)

支付宝问题解释:https://opensupport.alipay.com/support/helpcenter/168/201602495256?ant_source=zsearch

 

加好友:

1、根据授权之后拿到的authCode调用支付宝 alipay.system.oauth.token 获取userId,存入数据库;

2、设置一个中间页路由url,路由内部处理302重定向到 alipays://platformapi/startapp?appId=20000067&url=${encodeURIComponent(url)},后面跟的url参数就是加好友的路由地址,传入支付宝账号和userId参数;

3、加好友路由内部再重定向到alipays://platformapi/startapp?appId=20000186&actionType=addfriend&userId=userId&loginId=‘支付宝账号‘&source=by_f_v&alert=true

authCode置换userId的代码:

app.alipaySdk.exec(alipay.system.oauth.token, {
    appId: appId,
    grantType: authorization_code,
    code: authCode,
    refreshToken: token,
})

注意??:用支付宝开放平台开发助手生成的私钥是PKCS8格式的,需要转换成PKCS1格式,否则调用会报这个错:Error: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag

支付宝问题解释:https://opensupport.alipay.com/support/knowledge/20069/201602457250?ant_source=zsearch

 

附上支付宝开放平台的查找链接,有很多问题里面都能查到:https://opendocs.alipay.com/search

 

以上是关于支付宝对接授权及加好友的主要内容,如果未能解决你的问题,请参考以下文章

支付宝当面付怎么对接易支付

koa实现对接支付宝沙箱支付

前端对接后台支付(支付宝)

支付宝对接

android怎么和支付宝实现接口对接

H5自动唤起支付宝添加好友页面方法