VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
华纳云最新优惠促销活动
jtti最新优惠促销活动

重新编写打包百度支付(百度智能小程序支付)(百度支付叫什么)

locvps
主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

最近由于项目重建,百度支付被重新包装。这次增加了签名处理和用户退款,方便后期开发使用。

由于百度电商开放平台的升级,支付功能被搬到了智能小程序上。具体申请流程:百度收银支付开通指南,(https://smart program . Baidu . com/docs/operations/transform/pay/)。

(注意:在支付业务中,服务电话要填写银行预留手机号,如果填写不正确,会上报银行预留手机号格式验证失败。)

百度支付文档:百度收银接口2.0(https://smartprogram.baidu.com/docs/develop/function/tune _ up _ 2.0/)。

1.申请通过后,填写百度支付的相关配置:

$ config = array(& amp;#39;交易id & amp#39;= & gt& amp#39;& amp#39;//百度收银的财务结算凭证&;#39;app _ key & amp#39;= & gt& amp#39;& amp#39;,//表示应用程序标识的唯一ID#39;私人密钥& amp#39;= & gt& amp#39;& amp#39;,//私钥原始字符串&;#39;公钥& amp#39;= & gt& amp#39;& amp#39;//平台公钥&;#39;通知_网址& amp#39;= & gt& amp#39;& amp#39;,//支付回拨地址);第二,调用封装的支付方法,将返回的信息传递给百度小程序。

& lt?phpinclude & amp#39;。/Baidu pay . PHP & amp;#39;;$ Baidu pay = new \ feng \ Baidu pay($ config);$order_sn = time()。兰特(10009999);$ order = array(& amp;#39;身体与健康。#39;= & gt& amp#39;检验货物& amp;#39;//产品描述&;#39;总额及金额。#39;= & gt& amp#39;1 & amp#39;,//订单金额(分钟)&;#39;订单序号& amp#39;= & gt$order_sn,//订单号);$re = $baidupay->xcx pay($ order);die(JSON _ encode($ re));// JSON直接返回小程序客户端PHP小程序支付类xcxPay:

/** * [xcxPay百度小程序支付]* @ param[type]$ order[订单信息数组]* @ return[type][description]* $ order = array(* &;#39;身体与健康。#39;= & gt& amp#39;& amp#39;,//产品描述* &;#39;总额及金额。#39;= & gt& amp#39;& amp#39;,//订单金额(分钟)* &;#39;订单序号& amp#39;= & gt& amp#39;& amp#39;,//订单号*);*/公共静态函数xcxPay($order){ if(!is _ array($ order)| | count($ order)& lt;3)模具(& quot缺少数组数据信息!");$ config = self::$ config;$ requestParamsArr = array(& amp;#39;appKey & amp#39;= & gt$ config[& amp;#39;app _ key & amp#39;],& amp#39;dealId & amp#39;= & gt$ config[& amp;#39;交易id & amp#39;],& amp#39;tpOrderId & amp#39;= & gt$ order[& amp;#39;订单序号& amp#39;],& amp#39;总金额& amp#39;= & gt$ order[& amp;#39;总额及金额。#39;], );$ RSA sign = self::makeSign($ requestParamsArr,$ config[& amp;#39;私人密钥& amp#39;]);//声称百度支付签名$ bizinfo = array(&;#39;tpData & amp#39;= & gt数组(& quotappKey & quot= & gt$ config[& amp;#39;app _ key & amp#39;],& quotdealId & quot= & gt$ config[& amp;#39;交易id & amp#39;],& quottpOrderId & quot= & gt$ order[& amp;#39;订单序号& amp#39;],& quotrsaSign & quot= & gt$rsaSign,& quot总金额& quot= & gt$ order[& amp;#39;总额及金额。#39;],& quotreturnData & quot= & gt& amp#39;& amp#39;,& quot显示数据= & gt数组(& quotcashierTopBlock & quot= & gtarray(数组([& quot;leftCol&quot= & gt"订单名称",& quot右栏& quot= & gt$ order[& amp;#39;身体与健康。#39;] ],[& quot;leftCol&quot= & gt"数量",& quot右栏& quot= & gt"1 & quot],[& quot;leftCol&quot= & gt"订单金额",& quot右栏& quot= & gt$ order[& amp;#39;总额及金额。#39;] ])、数组([& quot;leftCol&quot= & gt"服务地址",& quot右栏& quot= & gt"北京市海淀区上地十街10号百度大厦],[& quot;leftCol&quot= & gt"服务时间”右栏& quot= & gt"2018/10/29 14:51 & quot;],[& quot;leftCol&quot= & gt"服务人员",& quot右栏& quot= & gt"百度App & quot])))),& quot交易标题& quot= & gt$ order[& amp;#39;身体与健康。#39;],& quotdealSubTitle & quot= & gt$ order[& amp;#39;身体与健康。#39;],& quotdealThumbView & quot= & gt"https://b . BD static . com/search box/icms/search box/img/swan -logo . png & quot;,),& quotorderDetailData & quot= & gt& amp#39;& amp#39;);$ b order = array(& amp;#39;dealId & amp#39;= & gt$ config[& amp;#39;交易id & amp#39;],& amp#39;appKey & amp#39;= & gt$ config[& amp;#39;app _ key & amp#39;],& amp#39;总金额& amp#39;= & gt$ order[& amp;#39;总额及金额。#39;],& amp#39;tpOrderId & amp#39;= & gt$ order[& amp;#39;订单序号& amp#39;],& amp#39;dealTitle & amp#39;= & gt$ order[& amp;#39;身体与健康。#39;],& amp#39;signFieldsRange & amp#39;= & gt1,& amp#39;rsaSign & amp#39;= & gt$ RSA sign & amp;#39;bizInfo & amp#39;= & gtjson_encode($bizInfo),);返回$ bdOrder}三、百度智能小程序的使用

天鹅

& ltview class = & quotwrap & quot& gt& ltview class = & quotcard -区域& quot& gt& lt按钮绑定:tap = & quotrequestPolymerPayment & quottype = & quot主要& quot悬停-停止-传播= & quottrue & quot& gt支付0.01元</button & gt;& lt/view & gt;& lt/view & gt;HTMLJS

page({ requestPolymerPayment(e){ swan . request({ URL:& amp;#39;https://mbd.baidu.com/xxx&第39名;//只是一个例子,不是真正的接口地址。开发人员从真实接口获取orderInfo的值。成功:res = & gt{ RES . data . data . deal title = & amp;#39;百度小程序演示支付测试& amp;#39;;设data = res.dataif (data.errno!= = 0){ console . log(& amp;#39;创建订单错误& amp#39;,数据);返回;} swan . requestpolymerpayment({ order info:data . data,success:RES = & gt;{ swan . show toast({ title:& amp;#39;支付成功&;#39;,图标:& amp#39;成功& amp#39;});console . log(& amp;#39;支付成功和。#39;,RES);},失败:err = & gt{ swan . show toast({ title:err . errmsg,icon:& amp;#39;无& amp#39;});console . log(& amp;#39;支付失败和。#39;,err);} });},失败:err = & gt{ swan . show toast({ title:& amp;#39;订单创建失败&;#39;,图标:& amp#39;无& amp#39;});console . log(& amp;#39;创建订单失败。#39;,err);} });}});第四,回款

& lt?phpinclude & amp#39;。/Baidu pay . PHP & amp;#39;;$ Baidu pay = new \ feng \ Baidu pay($ config);$re = $baidupay->notify();If ($re) {//这里回调处理订单操作//验证支付成功后返回的信息,可以直接操作订单。微信已获悉支付成功$ Baidu pay -& gt;success();//支付成功返回,通知结果} else {//支付失败$ Baidu pay -& gt;错误();//支付失败,返回状态(支付成功与否需要通知百度)}百度完整支付类(BaiduPay.php),包括小程序支付、签收、回拨、退款:

& lt?PHP/* * * * @作者:[冯]* @日期:2020-09-27t 16:28:3zhujicankao08:00 * @最后修改人:[冯]* @最后修改时间:2020-10-15t 10:23:07+08:00 */命名空间冯;class Baidu pay { private static $ config = array(& amp;#39;交易id & amp#39;= & gt& amp#39;& amp#39;//百度收银的财务结算凭证&;#39;app _ key & amp#39;= & gt& amp#39;& amp#39;,//表示应用程序标识的唯一ID#39;私人密钥& amp#39;= & gt& amp#39;& amp#39;,//私钥原始字符串&;#39;公钥& amp#39;= & gt& amp#39;& amp#39;//平台公钥&;#39;通知_网址& amp#39;= & gt& amp#39;& amp#39;,//支付回拨地址);/* * *[_ _ construct constructor]* @ param[type]$ config[转移支付相关配置]*/public function _ _ construct($ config = null){ $ config &;& ampself::$ config = $ config;} /** * [xcxPay百度小程序支付]* @ param[type]$ order[订单信息数组]* @ return[type][description]* $ order = array(* &;#39;身体与健康。#39;= & gt& amp#39;& amp#39;,//产品描述* &;#39;总额及金额。#39;= & gt& amp#39;& amp#39;,//订单金额(分钟)* &;#39;订单序号& amp#39;= & gt& amp#39;& amp#39;,//订单号*);*/公共静态函数xcxPay($order) { if(!is _ array($ order)| | count($ order)& lt;3)模具(& quot缺少数组数据信息!");$ config = self::$ config;$ requestParamsArr = array(& amp;#39;appKey & amp#39;= & gt$ config[& amp;#39;app _ key & amp#39;],& amp#39;dealId & amp#39;= & gt$ config[& amp;#39;交易id & amp#39;],& amp#39;tpOrderId & amp#39;= & gt$ order[& amp;#39;订单序号& amp#39;],& amp#39;总金额& amp#39;= & gt$ order[& amp;#39;总额及金额。#39;], );$ RSA sign = self::makeSign($ requestParamsArr,$ config[& amp;#39;私人密钥& amp#39;]);//声称百度支付签名$ bizinfo = array(&;#39;tpData & amp#39;= & gt数组(& quotappKey & quot= & gt$ config[& amp;#39;app _ key & amp#39;],& quotdealId & quot= & gt$ config[& amp;#39;交易id & amp#39;],& quottpOrderId & quot= & gt$ order[& amp;#39;订单序号& amp#39;],& quotrsaSign & quot= & gt$rsaSign,& quot总金额& quot= & gt$ order[& amp;#39;总额及金额。#39;],& quotreturnData & quot= & gt& amp#39;& amp#39;,& quot显示数据= & gt数组(& quotcashierTopBlock & quot= & gtarray(数组([& quot;leftCol&quot= & gt"订单名称",& quot右栏& quot= & gt$ order[& amp;#39;身体与健康。#39;] ],[& quot;leftCol&quot= & gt"数量",& quot右栏& quot= & gt"1 & quot],[& quot;leftCol&quot= & gt"订单金额",& quot右栏& quot= & gt$ order[& amp;#39;总额及金额。#39;] ])、数组([& quot;leftCol&quot= & gt"服务地址",& quot右栏& quot= & gt"北京市海淀区上地十街10号百度大厦],[& quot;leftCol&quot= & gt"服务时间”右栏& quot= & gt"2018/10/29 14:51 & quot;],[& quot;leftCol&quot= & gt"服务人员",& quot右栏& quot= & gt"百度App & quot])))),& quot交易标题& quot= & gt$ order[& amp;#39;身体与健康。#39;],& quotdealSubTitle & quot= & gt$ order[& amp;#39;身体与健康。#39;],& quotdealThumbView & quot= & gt"https://b . BD static . com/search box/icms/search box/img/swan -logo . png & quot;,),& quotorderDetailData & quot= & gt& amp#39;& amp#39;);$ b order = array(& amp;#39;dealId & amp#39;= & gt$ config[& amp;#39;交易id & amp#39;],& amp#39;appKey & amp#39;= & gt$ config[& amp;#39;app _ key & amp#39;],& amp#39;总金额& amp#39;= & gt$ order[& amp;#39;总额及金额。#39;],& amp#39;tpOrderId & amp#39;= & gt$ order[& amp;#39;订单序号& amp#39;],& amp#39;dealTitle & amp#39;= & gt$ order[& amp;#39;身体与健康。#39;],& amp#39;signFieldsRange & amp#39;= & gt1,& amp#39;rsaSign & amp#39;= & gt$ RSA sign & amp;#39;bizInfo & amp#39;= & gtjson_encode($bizInfo),);返回$ bdOrder}/* * *[退款百度支付退款]* @ param[type]$ order[订单信息]* @ param[type]$ type[退款类型]* $ order = array(* &;#39;身体与健康。#39;= & gt& amp#39;& amp#39;,//退款原因* &;#39;总额及金额。#39;= & gt& amp#39;& amp#39;,//退款金额(积分)* &;#39;订单序号& amp#39;= & gt& amp#39;& amp#39;,//订单号*&;#39;访问令牌& amp#39;= & gt& amp#39;& amp#39;//获取开发者的服务权限描述* &;#39;订单id & amp#39;= & gt& amp#39;& amp#39;,//百度本票ID * &;#39;用户id & amp#39;= & gt& amp#39;& amp#39;,//百度收银用户id *);*/公共静态函数退款($order=[],$ type = 1){ $ config = self::$ config;$ data = array(& amp;#39;访问令牌& amp#39;= & gt$ order[& amp;#39;访问令牌& amp#39;],//获取开发者服务权限描述&;#39;applyRefundMoney & amp#39;= & gt$ order[& amp;#39;总额及金额。#39;],//退款金额分钟。& amp#39;bizRefundBatchId & amp#39;= & gt$ order[& amp;#39;订单序号& amp#39;],//开发者退款批量&;#39;isSkipAudit & amp#39;= & gt1.//是否跳过审核,如果不要求百度要求开发者退还审核费用,请通过1;默认值为0;0:不要跳过开发者业务审核;1.跳过开发者商业评论。& amp#39;订单& amp#39;= & gt$ order[& amp;#39;订单id & amp#39;],//百度收银订单ID &;#39;退款理由和。#39;= & gt$ order[& amp;#39;身体与健康。#39;],//退款原因&;#39;退款类型& amp#39;= & gt$type,//退款类型1:用户发起的退款;2:开发商业务端的客服退款;3:开发者服务异常退款。& amp#39;tpOrderId & amp#39;= & gt$ order[& amp;#39;订单序号& amp#39;],//开发者订单id &;#39;用户& amp#39;= & gt$ order[& amp;#39;用户id & amp#39;],//百度收银用户id);$ array =[& amp;#39;errno & amp#39;= & gt0,& amp#39;味精& amp#39;= & gt& amp#39;成功& amp#39;,& amp#39;数据与信息。#39;= & gt[& amp;#39;isConsumed & amp#39;= & gt2] ];$ url = & amp#39;https://open API . Baidu . com/rest/2.0/smart app/pay/paymentservice/applyOrderRefund & amp;#39;;$response = self::post_curl($url,$ data);$result = json_decode($response,true);////显示错误消息//if($result[&;#39;味精& amp#39;]!= & amp#39;成功& amp#39;){ //返回false////die($ result[& amp;#39;味精& amp#39;]);// }返回$ result}/* * *[通知回调验证]* @ return[array][返回数组格式的通知数据]*/公共静态函数notify(){ $ data = $ _ post;//get XML $ config = self::$ config;如果(!$ data | | empty($ data[& amp;#39;rsaSign & amp#39;]))骰子(& amp#39;目前没有回拨信息&;#39;);$result = self::checkSign($data,$ config[& amp;#39;公钥& amp#39;]);//验证签名//判断签名是否正确并判断支付状态if($ result & amp;& amp$ data[& amp;#39;地位与责任。#39;]= = 2){ return $ data;} else {返回false} }/* *[成功通知支付状态]*/公共静态函数success(){ $ array =[&;#39;errno & amp#39;= & gt0,& amp#39;味精& amp#39;= & gt& amp#39;成功& amp#39;,& amp#39;数据与信息。#39;= & gt[& amp;#39;isConsumed & amp#39;= & gt2] ];die(JSON _ encode($ array));}/* * *[错误通知支付状态]*/公共静态函数error(){ $ array =[&;#39;errno & amp#39;= & gt0,& amp#39;味精& amp#39;= & gt& amp#39;成功& amp#39;,& amp#39;数据与信息。#39;= & gt[& amp;#39;iserrorrorder & amp;#39;= & gt1,& amp#39;isConsumed & amp#39;= & gt2] ];die(JSON _ encode($ array));} /** * [makeSign使用私钥生成签名字符串]* @ param array $ assocar[into parameter group]* @ param[type]$ rsalikeystr[私钥原始字符串,不带PEM格式的前缀和后缀]* @ return[type][签名结果字符串] */public静态函数making(array $ assocar,$ rsalikeystr){ $ sign = &;#39;& amp#39;;if(empty($ rsaPriKeyStr)| | empty($ assocar)){ return $ sign;}如果(!函数_ exists(& amp;#39;openssl _ pkey _ get _ private & amp#39;) || !函数_ exists(& amp;#39;openssl _ sign & amp#39;)){抛出新异常(& quotOpenssl扩展不存在”);} $ rsaPriKeyPem = self::convertrsakeystr 2 PEM($ rsaPriKeyStr,1);$ priKey = OpenSSL _ pkey _ get _ private($ rsaPriKeyPem);if(isset($ asso carr[& amp;#39;标志与广告。#39;]){ unset($ asso carr[& amp;#39;标志与广告。#39;]);} ksort($ asso carr);//参数按字典顺序排序$ parts = array();foreach($ asso carr as $ k = & gt;$ v){ $ parts[]= $ k & amp;#39;= & amp#39;。$ v;} $str =内爆(& amp#39;& amp& amp#39;,$ parts);openssl_sign($str,$sign,$ priKey);OpenSSL _ free _ key($ priKey);返回base64 _ encode($ sign);} /** * [checkSign使用公钥检查签名]* @ param array $assocArr[输入参数数据,签名属性名固定为RSA SIG]* @ param[type]$ rsapubkeystr[公钥原始字符串,不带PEM格式的前缀和后缀]* @ return[type][校验符号通过|假校验符号失败]*/公共静态函数校验符号(array $ asso carr,$ rsapubkeystr) {if(!isset($ asso carr[& amp;#39;rsaSign & amp#39;])| | empty($ assocar)| | empty($ rsaPubKeyStr)){ return false;}如果(!函数_ exists(& amp;#39;openssl _ pkey _ get _ public & amp#39;) || !函数_ exists(& amp;#39;openssl _ verify & amp#39;)){抛出新异常(& quotOpenssl扩展不存在”);} $ sign = $ asso carr[& amp;#39;rsaSign & amp#39;];unset($ asso carr[& amp;#39;rsaSign & amp#39;]);if(empty($ assocar)){返回false} ksort($ asso carr);//参数按字典顺序排序$ parts = array();foreach($ asso carr as $ k = & gt;$ v){ $ parts[]= $ k & amp;#39;= & amp#39;。$ v;} $str =内爆(& amp#39;& amp& amp#39;,$ parts);$ sign = base64 _ decode($ sign);$ rsaPubKeyPem = self::convertrsakeystr 2 PEM($ rsaPubKeyStr);$ pubKey = OpenSSL _ pkey _ get _ public($ rsaPubKeyPem);$ result =(bool)OpenSSL _ verify($ str,$sign,$ pubKey);OpenSSL _ free _ key($ pubKey);返回$ result} /** * [convertRSAKeyStr2Pem将密钥从字符串(无换行符)转换为Pem格式]* @ param[type]$ rsaKeyStr[原始密钥字符串] * @param integer $keyType [0公钥|1私钥,默认为0] * @return [type] [PEM格式密钥]*/公共静态函数convertrsakeystr 2 PEM($ rsaKeyStr,$ key type = 0){ $ PEM width = 64;$ rsaKeyPem = & amp#39;& amp#39;;$ begin = & amp#39;----BEGIN & amp;#39;;$ end = & amp#39;-----END & amp;#39;;$ key = & amp#39;-----& amp;#39;;$type = $keyType?& amp#39;RSA私人& amp#39;:& amp#39;公共& amp#39;;$keyPrefix = $begin。$type。$ key$keySuffix = $end。$type。$ key$rsaKeyPem。= $keyPrefix。"\ n & quot;$rsaKeyPem。= wordwrap($rsaKeyStr,$pemWidth,& quot\ n & quot,真)。"\ n & quot;$rsaKeyPem。= $ keySuffix如果(!函数_ exists(& amp;#39;openssl _ pkey _ get _ public & amp#39;) || !函数_ exists(& amp;#39;openssl _ pkey _ get _ private & amp#39;)){返回false} if($ key type = = 0 & amp;& ampfalse = = OpenSSL _ pkey _ get _ public($ rsaKeyPem)){ return false;} if($ key type = = 1 & amp;& ampfalse = = OpenSSL _ pkey _ get _ private($ rsaKeyPem)){ return false;}返回$ rsaKeyPem} /** * curl post请求* @param string $url地址* @param string $postData数据* @param array $header头* @ return bool | string * @ Date 2020/9/17 17:12 * @ Author wzb */public static function post _ curl($ URL = & amp;#39;& amp#39;,$ postData = & amp#39;& amp#39;,$ header =[]){ $ ch = curl _ init($ URL);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_HEADER,false);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5000);curl_setopt($ch,CURLOPT_TIMEOUT,5000);if($header){ curl_setopt($ch,CURLOPT_HTTPHEADER,$ header);} curl_setopt($ch,CURLOPT_POSTFIELDS,$ post data);$ result = curl _ exec($ ch);$httpCode = curl_getinfo($ch,curl info _ HTTP _ CODE);$ curlErrNo = curl _ errno($ ch);$ curlErr = curl _ error($ ch);curl _ close($ ch);返回$ result}}

这几篇文章你可能也喜欢:

本文由主机参考刊发,转载请注明:重新编写打包百度支付(百度智能小程序支付)(百度支付叫什么) https://zhujicankao.com/118291.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 重新编写打包百度支付(百度智能小程序支付)(百度支付叫什么)
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!