首页 > 作文

php实现单笔转账到支付宝功能

更新时间:2023-04-06 17:02:53 阅读: 评论:0

本文实例为大家分享了php实现单笔转账到支付宝的具体代码,供大家参考,具体内容如下

1.首先 去蚂蚁金服签约 单笔转账到支付宝

官方

2.需要的配置信息

1).应用appid

2).生成密钥

根据文档步骤生成

上传这里的 应用公钥

3.下载官方sdk 然后集成到自己项目

服务端sdk

官方实例

//实例化客户端alipayclient alipayclient = new defaultalipayclient("https://openapi.alipay.com/gateway.do", app_id, app_private_key, "json", chart, alipay_public_key, "rsa2");//实例化具体api对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.open.public.template.message.industry.modify alipayopenpublictemplatemessageindustrymodifyrequest request = new alipayopenpublictemplatemessageindustrymodifyrequest();//sdk已经封装掉了公共参数,这里只需要传入业务参数//此次只是参数展示,未进行字符串转义,实际情况下请转义request.tbizcontent(" {" +" \"primary_industry_name\":\"it科技/it软件与服务\"," +" \"primary_industry_code\":\"10001/20102\"," +" \"condary_industry_code\":\"10001/20102\"," +" \"condary_industry_name\":\"it科技/it软件与服务\"" +" }");alipayopenpublictemplatemessageindustrymodifyrespon respon = alipayclient.execute(request); //调用成功,则处理业务逻辑if(respon.issuccess()){ //.....}

效果如下

我的代码

<?php/** * create by 适可而止 * create time 2018/4/8 */namespace org\util;class alipaytransfer{ private $appid = 'appid'; private $rsaprivatekey = '私钥'; private $alipayrsapublickey = "支付宝公钥"; private $payer_name = "xx科技"; private $aop; public function __construct() {  $g_alipay = c('alipay_config');  $this->appid = $g_alipay['appid'];//appid  $this->rsaprivatekey = $g_alipay['rsaprivatekey']; //私钥  $this->alipayrsapublickey=$g_alipay['rsapublickey'];//支付宝公钥  //引入单笔转账sdk  vendor('alipayaop.aopsdk'); 保定金融学院}  public function init_aop_config() {  $this->aop->gatewayurl = 'https://openapi.alipay.com/gateway.do';  $this->aop->appid = $this->appid;  $this->aop->rsaprivatekey = $this->rsaprivatekey;  $this->aop->alipayrsapublickey=$this->alipayrsapublickey;  $this->aop->apiversion = '1.0';  $this->aop->signtype = 'rsa2';  $this->aop->postchart='utf-8';  $this->aop->format='json'; }  /**  * 单笔转账接口  * @param $order_number 订单号  * @param $pay_no  转账账号  * @param $pay_name  转账用户名  * @param $amount  转账金额  * @param $memo   备注  */ public function transfer($order_number,$pay_no,$pay_name,$amount,$memo) {  //存入转账日志  $this->transferlog($order_number,$pay_no,$pay_name,$amount);  $this->aop = new \aopclient ();  //配置参数  $this->init_aop_config();  //导入请求  $request = new \alipayfundtranstoaccounttransferrequest ();  $request->tbizcontent("{" .   "\"out_biz_no\":\"".$order_number."\"," .//商户生成订单号   "\"payee_type\":\"alipay_logonid\"," .//收款方支付宝账号类型   "\"payee_account\":\"".$pay_no."\"," .//收款方账号   "\"amount\":\"".$amount."\"," .//总金额   "\"payer_show_name\":\"".$this->payer_name."\"," .//付款方账户   "\"payee_real_name\":\"".$pay_name."\"," .//收款方姓名   "\"remark\":\"".$memo."\"" .//转账备注   "}");  $result = $this->aop->execute ( $request);  $responnode = str_replace(".", "_", $request->getapimethodname()) . "_respon";  $resultcode = $result->$responnode->code;  $resultsubmsg = $result->$responnode->sub_msg;  //修改转账日志  $this->edit_transferlog($order_number,$resultcode,$resultsubmsg);  if(!empt深圳儿童健康成长补贴y($resultcode)&&$resultcode == 10000){   return true;  } el {   return fal;  } }  /**  * 存取日志  */ private function transferlog($order_number,$pay_no,$pay_name,$amount) {  $data['order_number'] = $order_number;  $data['pay_no'] = $pay_no;  $data['pay_name'] = $pay_name;  $data['amount'] = $amount;  $data['create_time'] = time();  m('alipaytransferlog')->add($data); }  /**  * 修改日志  */ private function edit_transferlog($order_number,$result_code,$sub_msg) {  $model = d("alipaytransferlog");  $where['order_number'] = $order_number;  $result = $model->where($where)->order('create_time desc')->find(软件测试工资);  if ($result_code == 10000)  {   $result['status'] = 1;   $sub_msg = 'success';  }  el  {   $result['status'] = 2;  }  $result['memo'] = $sub_msg;  $result['update_time'] = time();  m('alipaytransferlog')->save($result); }  /**  * 查单接口  */ public function query($order_number) {  $this->aop = new \aopclient ();  //配置参数  $this->init_a烧烤活动方案op_config();  $request = new \alipayfundtransorderqueryrequest ();  $request->tbizcontent("{" .   "\"out_biz_no\":\"".$order_number."\"" .   " }");  $result = $this->aop->execute ( $request);  $responnode = str_replace(".", "_", $request->getapimethodname()) . "_respon";  $resultcode = $result->$responnode->code;  if(!empty($resultcode)&&$resultcode == 10000){   $res_arr['code'] = '00';   $res_arr['data'] = $result;  } el {   $res_arr['code'] = '-1';  }  return $res_arr; }}?>

以上公共管理类专业有哪些就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-06 17:02:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/8a08cba215ae9eb4b95f1694d505cc71.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:php实现单笔转账到支付宝功能.doc

本文 PDF 下载地址:php实现单笔转账到支付宝功能.pdf

标签:支付宝   参数   实例   接口
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图