TP5微信支付退款

2021-09-23 01:47:13 字數 3638 閱讀 1130

weixinpay .php

<?php

namespace;/*

*/use

think\log

;use

think\db

;use

think\cache

;class

weixinpay

/** * 退款

* @param float $totalfee 訂單金額 單位元

* @param float $refundfee 退款金額 單位元

* @param string $refundno 退款單號

* @param string $orderno 商戶訂單號

* @return string

*/public

function

dorefund

($totalfee

,$refundfee

,$refundno

,$wxorderno=''

,$orderno=''

)if($unifiedorder

->

return_code

!='success')if

($unifiedorder

->

result_code

!='success'

)return

true;}

public

static

function

curlget

($url=''

,$options

=array()

)//https請求 不驗證證書和host

curl_setopt

($ch

,curlopt_ssl_verifypeer

,false);

curl_setopt

($ch

,curlopt_ssl_verifyhost

,false);

$data

=curl_exec

($ch);

curl_close

($ch);

return

$data;}

public

function

curlpost

($url=''

,$postdata=''

,$options

=array()

)$ch

=curl_init()

;curl_setopt

($ch

,curlopt_url

,$url);

curl_setopt

($ch

,curlopt_returntransfer,1

);curl_setopt

($ch

,curlopt_post,1

);curl_setopt

($ch

,curlopt_postfields

,$postdata);

curl_setopt

($ch

,curlopt_timeout,30

);//設定curl允許執行的最長秒數if(

!empty

($options))

//https請求 不驗證證書和host

curl_setopt

($ch

,curlopt_ssl_verifypeer

,false);

curl_setopt

($ch

,curlopt_ssl_verifyhost

,false);

//第一種方法,cert 與 key 分別屬於兩個.pem檔案

//預設格式為pem,可以注釋

curl_setopt

($ch

,curlopt_sslcerttype

,'pem');

curl_setopt

($ch

,curlopt_sslcert

,"c:\***x\apiclient_cert.pem");

//絕對路徑

//預設格式為pem,可以注釋

curl_setopt

($ch

,curlopt_sslkeytype

,'pem');

curl_setopt

($ch

,curlopt_sslkey

,"c:\***x\apiclient_key.pem");

//絕對路徑

//第二種方式,兩個檔案合成乙個.pem檔案

// curl_setopt($ch,curlopt_sslcert,getcwd().'/all.pem');

$data

=curl_exec

($ch);

if($data

)else

}public

static

function

createnoncestr

($length=16

)return

$str;}

public

function

arraytoxml

($arr

)else

}$xml.=

"";return

$xml;}

public

static

function

xmltoarray

($xml

)public

static

function

getsign

($params

,$key

)protected

static

function

formatqueryparamap

($paramap

,$urlencode

=false

)$buff.=

$k."=".$v.

"&";}}

$reqpar=''

;if(strlen

($buff

)>0)

return

$reqpar;}

}

請求方法refund.php

<?php

/* * to change this license header, choose license headers in project properties.

* to change this template file, choose tools | templates

* and open the template in the editor.

*//**

* 2.錯誤碼參照 :

*/namespace;/*

*/use

think\log

;use

think\db

;use

think\cache

;include

'weixinpay.php'

;class

chrefund

echo

'refund fail';}

}

微信退款 tp5

老闆已經催促了好幾個月了。今天實在是沒有辦法了,那就給他寫了吧,原來沒有寫過退款 看文件還是看了很久的,雖然說官方給的demo 但是還是看一下比較好 就當是學習了嘛 好了,廢話不多說 開始上菜 因為是第一次做退款 咱們還是直接用demo裡面的 首先呢 匯入類庫 loader import paywx...

TP5微信支付

public function pay openid,fee,test openid openid 支付相關設定 fee i post.total fee fee fee 舉例支付0.01 body test nonce str this nonce str 隨機字串 out trade no th...

tp5微信app支付

支付時例項化該類,呼叫pay方法即可 需要傳引數 namespace use think db class wxpay else return json encode data public function sign data wx key stringsigntemp stringa key 6...