php 微信支付V3 APP支付

2022-09-16 16:27:16 字數 2981 閱讀 5722

<?php

class

wechat

$this->wechat_config = $wechat_config

; }

//生成預支付訂單

public

function wx_pay($body,$total_fee,$out_trade_no,$attach = 'charge_order')

else

//設定header

curl_setopt($ch, curlopt_sslversion,curl_sslversion_tlsv1);

curl_setopt(

$ch, curlopt_header, false

);

//要求結果為字串且輸出到螢幕上

curl_setopt($ch, curlopt_returntransfer, true

);

//設定超時

curl_setopt($ch, curlopt_timeout, 30);

curl_setopt(

$ch, curlopt_post, true

);

//傳輸檔案

curl_setopt($ch, curlopt_postfields, $xml

);

//執行curl

$data = curl_exec($ch

);

//返回結果

if($data

)

else

} else

}//引數要組裝成xml格式

public

static

function toxml($data = array

())

$xml = "";

foreach ($data

as$key => $val

) else

}$xml .= "";

return

$xml

; }

public

static

function fromxml($xml

)

//將xml轉為array

//禁止引用外部xml實體

libxml_disable_entity_loader(true

);

$data = json_decode(json_encode(******xml_load_string($xml, '******xmlelement', libxml_nocdata)), true

);

return

$data

; }

//生成隨機字串

private

function

rand_code()

/*獲取當前伺服器的ip

//生成簽名

public

static

function getsign($params,$api_key

) }

$stringa = implode("&", $newarr); //

使用 & 符號連線引數

$stringsigntemp = $stringa."&key=".$api_key; //

拼接key

// key是在商戶平台api安全裡自己設定的

$stringsigntemp = md5($stringsigntemp); //

將字串進行md5加密

$sign = strtoupper($stringsigntemp); //

將所有字元轉換為大寫

return

$sign

; }

}

//

$wechat_config =[

'mch_id'=>$this->config->openweixin->mch_id,

'api_key'=>$this->config->openweixin->api_key,

'notify_url'=>$this->config->openweixin->notify_url,];

$order_no = date('ymdhis').rand(1000,9999);

$money = 1;

$wechat = new wechat($wechat_config

);

$wechat_data = $wechat->wx_pay('test',$money,$order_no,'aid_order');

if($wechat_data['code'] != 200)

$result = [ 'order_no'=>$order_no , 'money'=>$money, 'wechat_data'=>$wechat_data,];

print_r($result);die;

//

public

function

wx_notifyaction()}}

elseif($data['attach'] == 'rescue_order')}}

//if($res == true

)else

}//支付失敗,輸出錯誤資訊

else

}else

}

微信支付 退款 v3版微信支付

證書 apiclient cert.p12。jar包 commons codec 1.6.jar commons logging 1.1.3.jar fluent hc 4.3.4.jar httpclient 4.3.4.jar httpclient cache 4.3.4.jar httpcor...

php 對接微信APP支付

開發前準備 應用簽名和應用包名如何寫,如果你是用apicloud開發的,前端會知道的,具體可參考官方文件 下面我們就可以開始開發了 支付流程 1.先呼叫統一下單api生成預付訂單 2.獲取到prepay id後將引數再次簽名 4.支付成功,非同步 具體看 wxpay是處理支付的 namespace ...

微信app支付

商戶id public static final string partner id 14698sdfs402dsfdew402 常量固定值 public static final string grant type client credential 獲取預支付id的介面url public st...