Skip to content

Latest commit

 

History

History
189 lines (160 loc) · 6.04 KB

支付宝.md

File metadata and controls

189 lines (160 loc) · 6.04 KB

目录

转账到支付宝

支付宝转账文档 https://doc.open.alipay.com/docs/api.htm?apiId=1321&docType=4

var axios = require ('axios');
var notify_url="......."
var baseParams = {
  app_id:'2020202020202020',
  charset: 'utf-8',
  format:'JSON',
  sign:'',
  sign_type:'RSA2',
  timestamp:moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  version:"1.0"
}

(1). 转账参数---第一种方式
var transferParams = Object.assign({
  method:"alipay.trade.app.pay",
  biz_content:{
    out_biz_no:null,
    payee_type:'ALIPAY_LOGONID',
    payee_account:'支付宝登录号,支持邮箱和手机号格式',
    amount:0,
    payer_show_name:'付款方姓名',
    payee_real_name:null,
    remark:'转账备注'
  }
},baseParams)

(2).转账参数---第二种方式
var transferParams = Object.assign({
  method:"alipay.trade.app.pay",
  biz_content:{
    out_biz_no:null,
    payee_type:'ALIPAY_USERID',
    payee_account:'以2088开头的16位纯数字组成',
    amount:0,
    payer_show_name:'付款方姓名',
    payee_real_name:null,
    remark:'转账备注'
  }
},baseParams)

getTransferUrl:function(transfer_id){
  return new Promise(fucntion(resolve,reject){
    var biz_content = {
      out_biz_no:`ZP_1`,
      payee_type:'ALIPAY_LOGONID',
      payee_account:110110110,
      amount:10,
      payer_show_name:'转账付款方姓名',
      payer_real_name:'收款真实姓名',
      remark:'转账备注'
    };
    // 构建签名对象
    var singObj = transferParams ;
    signObj.biz_content = JSON.stringify(biz_content);
    // 签名
    resolve(SignTool.getUrl(signObj));
  }).catch(function(err){
    reject(err);
    })
}

...


Transfer:function(req,res){
  var transfer_id = req.params.transfer_id;
  if(!transfer_id) return res.json({code:1,message:'转账id未传'})
  return this.getTransferUrl(transfer_id).then(function(url){
    var domain = 'https://openapi.alipay.com/gateway.do' ;
    return axios.get(`${domain}?${url}`).then(function(response){
       var transfer = response.data.alipay_fund_trans_toaccount_transfer_response ;
       if(transfer.code ==='10000'){
         ...
          res.json({code:0,message:'转账成功'})
       }else{
        res.json({code:1,message:'转账失败'})
       } 
    }).catch(function(err){
      res.json({code:1,message:'转账失败'})
    })
  })
}


支付宝授权

  • 1.URL拼接 https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=SCOPE&redirect_uri=ENCODED_UR

    (支付宝拼接获取auth_code)apiname=com.alipay.account.auth&app_id=2016sdfsdf945236&app_name=mc&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get&pid=20sdfsdfsdf5791034&product_id=APP_FAST_LOGIN&scope=kuaijie&sign_type=RSA2&target_id=149asdasd225474&sign=Kppa4XQunq0Z71uOKCscpDEgeCI0LZqSUm0bsdjQSRpt3FPuSDlawJeyH0ksaBbC7OlqZ2tc434nsi%2BUaIgnXKXnAe0qwchuynq0yq0i1zaHfmM7r52Sdhx56VSap0xoR%2Bpy1%2FBzs5agM0GrpxBbmOLJOey1E35qL6aRoerHkrr95GC9feTdUpRX1g5UDtNgke9xvICHU204RZz2%2BnRG5rwk1p7GPq38oVFc7PNIQe3EZn33C%2Bqo0zyVLiPkOsQ%2BPfuGnWUaH7u%2BR%2B%2BVUmG1%2FjyBqTljupkW7mpL91E%2B203%2FchLpZPsgCi8r%2BAAF3ktXTOt5G3BiTUnxVFacHgiGhQ%3D%3D

  • 2.获取auth_code

http://example.com/doc/toAuthPage.html?app_id=2014101500013658&source=alipay_wallet&scope=auth_userinfo&auth_code=ca34ea491e7146cc87d25fca24c4cD11

  • 3.使用auth_code换取接口access_token及用户userId

  • 请求

REQUEST URL: https://openapi.alipay.com/gateway.do
REQUEST METHOD: POST
CONTENT:
    app_id=2014070100171525
    method=alipay.system.oauth.token
    charset=GBK
    sign_type=RSA2
    timestamp=2014-01-01 08:08:08
    sign=rXaTEfJ7WTDsP1DWRPHARW3uOr19+fzlngMCJBvbhP1XPEa9qZwGGng9oMDloABpJMT2SGeOj46+BUkqCGRO9fH90Vci3hOH01BfYnbhJz3ADK2h7gpjlponx4/sxELN6f2GXi51XKiHKnxMA9XpLLo68q+roY0M/ZFQ1UdnqeM=
    version=1.0
    grant_type=authorization_code
    code=4b203fe6c11548bcabd8da5bb087a83b
    refresh_token=201208134b203fe6c11548bcabd8da5bb087a83b
  • 响应
{
    "alipay_system_oauth_token_response": {
        "access_token": "publicpBa869cad0990e4e17a57ecf7c5469a4b2",
        "user_id": "2088411964574197",
        "alipay_user_id": "20881007434917916336963360919773",
        "expires_in": 300,
        "re_expires_in": 300,
        "refresh_token": "publicpB0ff17e364f0743c79b0b0d7f55e20bfc"
    },
    "sign": "xDffQVBBelDiY/FdJi4/a2iQV1I7TgKDFf/9BUCe6+l1UB55YDOdlCAir8CGlTfa0zLYdX0UaYAa43zY2jLhCTDG+d6EjhCBWsNY74yTdiM95kTNsREgAt4PkOkpsbyZVXdLIShxLFAqI49GIv82J3YtzBcVDDdDeqFcUhfasII="
}
  • 4.调用接口获取用户信息

  • 请求

REQUEST URL: https://openapi.alipay.com/gateway.do
REQUEST METHOD: POST
CONTENT:
    method=alipay.user.userinfo.share
    timestamp=2014-07-29 20:30:30
    app_id=2014070100171523
    auth_token=publicpB9ea460ff5b5c468c9ccf5e967dc34963
    charset=GBK
    version=1.0
    sign_type=RSA2
    sign=R48FPxFxDSzred4JQ+sLsjzzNen5eZVjVcOgepxBgNFwhIxn0XrqDR53Di6fv1nLMIGEDm0VyGq516J8sVj4rlUSLehHy+oN7s7m07dYk+6xHpoIz4A1+N2tlCmtiHslWGxF6KMEYVjZLHo/y7tEwHQJ6r4H1svT3CJJ2HJpK1o=
  • 响应
{
    "alipay_user_userinfo_share_response": {
        "avatar": "https:\/\/tfsimg.alipay.com\/images\/partner\/T1k0xiXXRnXXXXXXXX",
        "nick_name": "张三",
        "city": "杭州",
        "province": "浙江省",
        "gender" : "M",
        "user_type_value": "2",
        "is_licence_auth": "F",
        "is_certified": "T",
        "is_certify_grade_a": "T",
        "is_student_certified": "F",
        "is_bank_auth": "T",
        "is_mobile_auth": "T",
        "alipay_user_id": "2088102015433735",
        "user_id": "20881007434917916336963360919773",
        "user_status": "T",
        "is_id_auth": "T"
    },
    "sign": "jhoSkfE7BTIbwEx0L8/H0GU0Z2DOZYIJlrUMyJL8wwwInVeXfz+CWqx0V2b3FvhMQSrb74dkzDQpGXGdZQZMldGe4+FSEQU1V3tWijpO9ZisNJnEpF+U2lQ7IUMLsgjjx9a0IdMwvXlqz1HPrmFZQjG2dvlFyXhi07HcEnVOJZw="
}