超碰中文网,91久久精品日日躁夜夜躁欧美,一区二区三区精品道,一区二区国产在线观看,亚洲精品中文字幕乱码一区二区,天天看片高清影视在线观看,久久99精品久久久久蜜桃,久久成人影视

VPS參考測評推薦
專注分享VPS主機優惠信息
衡天云優惠活動
熱網互聯2026年促銷活動
hostkvm優惠促銷活動
zji優惠促銷活動
QQGNET優惠促銷活動
QQGNET優惠促銷活動

重新編寫打包百度支付(百度智能小程序支付)

主機參考: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/)

一、申請通過后,填寫百度支付相關配置:

$ config = array( # 39;deal _ id # 39= gt''、//百度收銀的財務結算憑證 # 39;app _ key # 39= gt'',//代表應用程序身份的唯一 # 39private _ key # 39= gt'',//私鑰的原始字符串 # 39;public _ key # 39= gt'',//平臺公鑰 # 39;notify _ url # 39= gt'',//支付回撥地址);第二,調用封裝好的支付方法,將返回的信息傳遞給百度小程序。

lt馬鞭phpinclude # 39。/Baidu pay . PHP # 39;;$ Baidu pay = new \ feng \ Baidu pay($ config);$order_sn = time()。蘭特(10009999);$ order = array( # 39;正文 # 39;= gt'測試商品 # 39;,//產品描述 # 39;total _ amount # 39= gt'1',//訂單金額(積分) # 39;order _ sn # 39= gt$order_sn,//訂單號);$re = $baidupay->xcx pay($ order);die(JSON _ encode($ re));// JSON直接返回applet客戶端PHP applet支付類xcxPay:

/** * [xcxPay百度小程序支付]* @ param[type]$ order[訂單信息數組]* @ return[type][description]* $ order = array(* # 39;正文 # 39;= gt'',//產品描述* # 39;total _ amount # 39= gt'',//訂單金額(積分)* # 39;order _ sn # 39= gt'',//訂單號*);*/公共靜態函數xcxPay($order){ if(!is _ array($ order)| | count($ order) lt;3)模具( 缺少數組數據信息!");$ config = self::$ config;$ requestParamsArr = array( # 39;appKey # 39= gt$ config[ # 39;app _ key # 39], 'dealId # 39= gt$ config[ # 39;deal _ id # 39], 'tpOrderId # 39= gt$ order[ # 39;order _ sn # 39], '總金額 # 39;= gt$ order[ # 39;total _ amount # 39], );$ RSA sign = self::makeSign($ requestParamsArr,$ config[ # 39;private _ key # 39]);//認領百度的支付簽名$ bizInfo = array( # 39;tpData # 39= gt數組( appKey = gt$ config[ # 39;app _ key # 39], dealId = gt$ config[ # 39;deal _ id # 39], tpOrderId = gt$ order[ # 39;order _ sn # 39], rsaSign = gt$rsaSign, 總金額 = gt$ order[ # 39;total _ amount # 39], returnData = gt'', 顯示數據= gt數組( cashierTopBlock = gtarray(數組([ ;leftCol= gt"訂單名稱", 右欄 = gt$ order[ # 39;正文 # 39;] ],[ ;leftCol= gt"數量", 右欄 = gt"1 ],[ ;leftCol= gt"訂單金額", 右欄 = gt$ order[ # 39;total _ amount # 39] ])、數組([ ;leftCol= gt"地址", 右欄 = gt"北京市海淀區上地十街10號百度大廈],[ ;leftCol= gt"服務", 右欄 = gt"2018/10/29 14:51 ;],[ ;leftCol= gt"服務", 右欄 = gt"百度App ]))), ;交易標題 = gt$ order[ # 39;正文 # 39;], dealSubTitle = gt$ order[ # 39;正文 # 39;], dealThumbView = gt"https://b . BD static . com/search box/icms/search box/img/swan -logo . png ;,), orderDetailData = gt'');$ b order = array( # 39;dealId # 39= gt$ config[ # 39;deal _ id # 39], 'appKey # 39= gt$ config[ # 39;app _ key # 39], '總金額 # 39;= gt$ order[ # 39;total _ amount # 39], 'tpOrderId # 39= gt$ order[ # 39;order _ sn # 39], 'dealTitle # 39= gt$ order[ # 39;正文 # 39;], 'signFieldsRange # 39= gt1, 'rsaSign # 39= gt$rsaSign, # 39;bizInfo # 39= gtjson_encode($bizInfo),);返回$ bdOrder}三、百度智能小程序的使用

天鵝

ltview class = wrap gt ltview class = card -區域 gt lt按鈕綁定:tap = requestPolymerPayment type = 主要 懸停-停止-傳播= true gt支付0.01元</button gt; lt/view gt; lt/view gt;HTMLJS

page({ requestPolymerPayment(e){ swan . request({ URL: # 39;https://mbd.baidu.com/xxx',//這只是一個例子,不是真正的接口地址。開發者從真實接口success中獲取orderInfo的值:RES = >;{ RES . data . data . deal title = # 39;百度小程序演示支付測試 # 39;;設data = res.dataif (data.errno!= = 0){ console . log( # 39;創建訂單錯誤 # 39;,數據);返回;} swan . requestpolymerpayment({ order info:data . data,success:RES = gt;{ swan . show toast({ title: # 39;支付成功 # 39;,圖標: # 39;成功 # 39;});console . log( # 39;支付成功 # 39;,RES);},失敗:err = gt{ swan . show toast({ title:err . errmsg,icon: # 39;無 # 39;});console . log( # 39;支付失敗 # 39;,err);} });},失敗:err = gt{ swan . show toast({ title: # 39;訂單創建失敗 # 39;,圖標: # 39;無 # 39;});console . log( # 39;創建訂單失敗 # 39;,err);} });}});四。支付回撥

lt馬鞭phpinclude # 39。/Baidu pay . PHP # 39;;$ Baidu pay = new \ feng \ Baidu pay($ config);$re = $baidupay->notify();If ($re) {//這里回調訂單處理操作//驗證支付成功后返回的信息,可以直接操作訂單。微信已通知$ baidupay->支付成功;success();//支付返回成功,結果通知} else {//支付失敗$ Baidu pay ->;錯誤();//如果支付失敗,返回狀態(支付成功與否需要通知百度)}百度完整的支付類(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( # 39;deal _ id # 39= gt''、//百度收銀的財務結算憑證 # 39;app _ key # 39= gt'',//代表應用程序身份的唯一 # 39private _ key # 39= gt'',//私鑰的原始字符串 # 39;public _ key # 39= gt'',//平臺公鑰 # 39;notify _ url # 39= gt'',//支付回撥地址);/* * *[_ _ construct constructor]* @ param[type]$ config[轉移支付相關配置]*/public function _ _ construct($ config = null){ $ config ;self::$ config = $ config;} /** * [xcxPay百度小程序支付]* @ param[type]$ order[訂單信息數組]* @ return[type][description]* $ order = array(* # 39;正文 # 39;= gt'',//產品描述* # 39;total _ amount # 39= gt'',//訂單金額(積分)* # 39;order _ sn # 39= gt'',//訂單號*);*/公共靜態函數xcxPay($order) { if(!is _ array($ order)| | count($ order) lt;3)模具( 缺少數組數據信息!");$ config = self::$ config;$ requestParamsArr = array( # 39;appKey # 39= gt$ config[ # 39;app _ key # 39], 'dealId # 39= gt$ config[ # 39;deal _ id # 39], 'tpOrderId # 39= gt$ order[ # 39;order _ sn # 39], '總金額 # 39;= gt$ order[ # 39;total _ amount # 39], );$ RSA sign = self::makeSign($ requestParamsArr,$ config[ # 39;private _ key # 39]);//認領百度的支付簽名$ bizInfo = array( # 39;tpData # 39= gt數組( appKey = gt$ config[ # 39;app _ key # 39], dealId = gt$ config[ # 39;deal _ id # 39], tpOrderId = gt$ order[ # 39;order _ sn # 39], rsaSign = gt$rsaSign, 總金額 = gt$ order[ # 39;total _ amount # 39], returnData = gt'', 顯示數據= gt數組( cashierTopBlock = gtarray(數組([ ;leftCol= gt"訂單名稱", 右欄 = gt$ order[ # 39;正文 # 39;] ],[ ;leftCol= gt"數量", 右欄 = gt"1 ],[ ;leftCol= gt"訂單金額", 右欄 = gt$ order[ # 39;total _ amount # 39] ])、數組([ ;leftCol= gt"地址", 右欄 = gt"北京市海淀區上地十街10號百度大廈],[ ;leftCol= gt"服務", 右欄 = gt"2018/10/29 14:51 ;],[ ;leftCol= gt"服務", 右欄 = gt"百度App ]))), ;交易標題 = gt$ order[ # 39;正文 # 39;], dealSubTitle = gt$ order[ # 39;正文 # 39;], dealThumbView = gt"https://b . BD static . com/search box/icms/search box/img/swan -logo . png ;,), orderDetailData = gt'');$ b order = array( # 39;dealId # 39= gt$ config[ # 39;deal _ id # 39], 'appKey # 39= gt$ config[ # 39;app _ key # 39], '總金額 # 39;= gt$ order[ # 39;total _ amount # 39], 'tpOrderId # 39= gt$ order[ # 39;order _ sn # 39], 'dealTitle # 39= gt$ order[ # 39;正文 # 39;], 'signFieldsRange # 39= gt1, 'rsaSign # 39= gt$rsaSign, # 39;bizInfo # 39= gtjson_encode($bizInfo),);返回$ bdOrder}/* * *[退款百度支付退款]* @ param[type]$ order[訂單信息]* @ param[type]$ type[退款類型]* $ order = array(* # 39;正文 # 39;= gt'',//退款原因* # 39;total _ amount # 39= gt'',//退款金額(積分)* # 39;order _ sn # 39= gt'',//訂單號* '訪問令牌 # 39;= gt'',//獲取開發者服務權限描述* # 39;order _ id # 39= gt'',//百度收銀訂單ID * # 39user _ id # 39= gt'',//百度收銀用戶id *);*/公共靜態函數退款($order=[],$ type = 1){ $ config = self::$ config;$ data = array( # 39;訪問令牌 # 39;= gt$ order[ # 39;訪問令牌 # 39;],//獲取開發者服務權限描述 # 39;applyRefundMoney # 39= gt$ order[ # 39;total _ amount # 39],//退款金額分鐘。'bizRefundBatchId # 39= gt$ order[ # 39;order _ sn # 39],//開發商退款批量 # 39;isSkipAudit # 39= gt1.//是否跳過審批,如果百度不需要向開發者要求退款審批,請通過1。默認值為0;0:不跳過開發者業務端的審核;1:跳過開發者業務審計。'訂單編號 # 39;= gt$ order[ # 39;order _ id # 39],//百度收銀訂單ID # 39退款理由 # 39;= gt$ order[ # 39;正文 # 39;],//退款原因 # 39;退款類型 # 39;= gt$type,//退款類型1:用戶發起退款;2:開發商業務方客服退款;3:開發者服務異常退款。'tpOrderId # 39= gt$ order[ # 39;order _ sn # 39],//開發者訂單ID # 39userId # 39= gt$ order[ # 39;user _ id # 39],//百度收銀用戶id);$ array =[ # 39;errno # 39= gt0, 'msg # 39= gt'成功 # 39;, '數據 # 39;= gt['isConsumed # 39= gt2] ];$ url = # 39https://open API . Baidu . com/rest/2.0/smart app/pay/paymentservice/applyOrderRefund # 39;;$response = self::post_curl($url,$ data);$result = json_decode($response,true);////顯示錯誤消息//if($result[ # 39;msg # 39]!='成功 # 39;){ //返回false////die($result[ # 39;msg # 39]);// }返回$ result}/* * *[通知回調驗證]* @ return[array][以數組格式返回通知數據]*/公共靜態函數notify(){ $ data = $ _ post;//Get XML $ config = self::$ config;如果(!$ data | | empty($ data[ # 39;rsaSign # 39]))死( # 39;還沒有回撥信息 # 39;);$result = self::checkSign($data,$ config[ # 39;public _ key # 39]);//驗證簽名//判斷簽名是否正確。判斷付款狀態,如果(result $ data[ # 39;地位 # 39;]= = 2){ return $ data;} else {返回false} }/* * *[成功通知支付狀態]*/公共靜態函數success(){ $ array =[ # 39;errno # 39= gt0, 'msg # 39= gt'成功 # 39;, '數據 # 39;= gt['isConsumed # 39= gt2] ];die(JSON _ encode($ array));}/* * *[錯誤通知支付狀態]*/公共靜態函數error(){ $ array =[ # 39;errno # 39= gt0, 'msg # 39= gt'成功 # 39;, '數據 # 39;= gt['iserrorrorder # 39;= gt1, 'isConsumed # 39= gt2] ];die(JSON _ encode($ array));} /** * [makeSign使用私鑰生成簽名字符串]* @ param array $ assocar[into parameter group]* @ param[type]$ rsaPriKeyStr[私鑰原始字符串,不含PEM格式前綴和后綴]* @ return[type][簽名結果字符串] */public靜態函數設計(array $ assocar,$ rsaPriKeyStr){ $ sign = # 39;';if(empty($ rsaPriKeyStr)| | empty($ assocar)){ return $ sign;}如果(!function _ exists( # 39;openssl _ pkey _ get _ private # 39) || !function _ exists( # 39;openssl _ sign # 39)){拋出新異常( Openssl擴展不存在”);} $ rsaPriKeyPem = self::convertrsakeystr 2 PEM($ rsaPriKeyStr,1);$ priKey = OpenSSL _ pkey _ get _ private($ rsaPriKeyPem);if(isset($ asso carr[ # 39;標志 # 39;]){ unset($ asso carr[ # 39;標志 # 39;]);} ksort($ asso carr);//參數按照字典順序$parts = array()排序;foreach($ asso carr as $ k = gt;$ v){ $ parts[]= $ k . # 39;='。$ v;} $str =內爆( # 39; ',$ parts);openssl_sign($str,$sign,$ priKey);OpenSSL _ free _ key($ priKey);返回base64 _ encode($ sign);} /** * [checkSign使用公鑰驗證簽名]* @ param array $ asso carr[根據輸入參數,簽名屬性名固定為r sign]* @ param[type]$ rsapubkeystr[公鑰的原始字符串,不帶PEM格式的前綴和后綴]* @ return[type][check pass | false check fail]*/公共靜態函數check sign (array $ assocarr,$ rsapubkeystr) {if(!isset($ asso carr[ # 39;rsaSign # 39])| | empty($ assocar)| | empty($ rsaPubKeyStr)){ return false;}如果(!function _ exists( # 39;openssl _ pkey _ get _ public # 39) || !function _ exists( # 39;openssl _ verify # 39)){拋出新異常( Openssl擴展不存在”);} $ sign = $ asso carr[ # 39;rsaSign # 39];unset($ asso carr[ # 39;rsaSign # 39]);if(empty($ assocar)){返回false} ksort($ asso carr);//參數按照字典順序$parts = array()排序;foreach($ asso carr as $ k = gt;$ v){ $ parts[]= $ k . # 39;='。$ v;} $str =內爆( # 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] default * @ return [type] [PEM格式密鑰]*/公共靜態函數convertrsakeystr 2 PEM($ RSA keystr,$ key type = 0){ $ PEM width = 64;$ rsaKeyPem = # 39';$ begin = # 39-----BEGIN # 39;;$ end = # 39-----END # 39;;$ key = # 39key ----- # 39;;$type = $keyType?'RSA PRIVATE # 39: 'PUBLIC # 39;$keyPrefix = $begin。$type。$ key$keySuffix = $end。$type。$ key$rsaKeyPem。= $keyPrefix。"\ n ;$rsaKeyPem。= wordwrap($rsaKeyStr,$pemWidth, \ n ,真)。"\ n ;$rsaKeyPem。= $ keySuffix如果(!function _ exists( # 39;openssl _ pkey _ get _ public # 39) || !function _ exists( # 39;openssl _ pkey _ get _ private # 39)){返回false} if($ key type = = 0 ; false = = OpenSSL _ pkey _ get _ public($ rsaKeyPem)){ return false;} if($ key type = = 1 ; false = = 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靜態函數post _ curl($ URL = # 39;',$ postData = # 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}}以上是對百度支付(百度智能小程序支付)進行改寫和打包的詳細內容。請多關注主機參考其他相關文章!

這幾篇文章你可能也喜歡:

本文由主機參考刊發,轉載請注明:重新編寫打包百度支付(百度智能小程序支付) http://www.k2270.com/77958.html

【騰訊云】領8888元采購禮包,搶爆款云服務器 每月 9元起,個人開發者加享折上折!
打賞
轉載請注明原文鏈接:主機參考 » 重新編寫打包百度支付(百度智能小程序支付)
主機參考僅做資料收集,不對商家任何信息及交易做信用擔保,購買前請注意風險,有交易糾紛請自行解決!請查閱:特別聲明

評論 搶沙發

評論前必須登錄!