thinkphp5 微信支付微信提現開箱即用

2021-09-24 15:23:21 字數 2896 閱讀 2762

<?php

use think\db;

/** */

class wxpay extends api

parent::_initialize();

}/**

* 獲取預支付訂單

** @apisummary (獲取預支付訂單)

* @apiparams (name="token", type="string", required=true, description="會員token")

* @apiparams (name="total_fee", type="string", required=true, description="金額")

*/

public function getprepayorder()

/**@apiinternal

*執行第二次簽名,才能返回給客戶端使用

*/public function getorder($prepayid)

/**@apiinternal

*生成簽名

*/public function getsign($obj)

//簽名步驟一:按字典序排序引數

ksort($parameters);

$string = $this->formatbizqueryparamap($parameters, false);

//echo "【string】 =".$string."

"; //簽名步驟二:在string後加入key

$string = $string."&key=".$this->config["key"];

// echo "

"; //簽名步驟三:md5加密

$result_ = strtoupper(md5($string));

return $result_;}/*

*@apiinternal

*獲取指定長度的隨機字串

*/public function getrandchar($length)

return $str;

}//陣列轉xml

private function arraytoxml($arr)

else

$xml.="<".$key.">";

}$xml.="";

return $xml;}/*

*@apiinternal

*post https請求,curlopt_postfields xml格式

*/public function postxmlcurl($xml,$url,$second=30)

else

}/*

* @apiinternal

* 獲取當前伺服器的ip

* 將陣列轉成uri字串

*/public function formatbizqueryparamap($paramap, $urlencode)

$buff .= strtolower($k) . "=" . $v . "&";

}$reqpar;

if (strlen($buff) > 0)

return $reqpar;

}public function xmlstr_to_array($xml,$isfile=false)else

$result= json_decode(json_encode(******xml_load_string($xmlstr, '******xmlelement', libxml_nocdata)), true);

return $result;

}public function paynotify()}}

/***

* @apiparams (name="token", type="string", required=true, description="token")

* @apiparams (name="amount", type="string", required=true, description="金額")

* @apiparams (name="remarks", type="string", required=true, description="備註")

*/

public function widthdraw()

$str.='key='.$secrect_key;

$data['sign'] = md5($str);

$xml = $this->arraytoxml($data);

$url=''; //呼叫介面

$res = $this->wx_curl($xml,$url);

if ($res) );

$this->success('ok');

return $res;

}else

} public function wx_curl($vars,$url,$second = 30, $aheader = array())

curl_setopt($ch, curlopt_post, 1);//post提交方式

curl_setopt($ch, curlopt_postfields, $vars);//全部資料使用http協議中的"post"操作來傳送

$data = curl_exec($ch);//執行回話

if ($data) else

}}

ThinkPHP5 整合微信掃碼支付

注意 notify url 要寫絕對路徑 mchid 商戶號 必須配置,開戶郵件中可檢視 var string 得到的qrcode url 需要賦值到前端頁面標籤的url 注意外網可訪問的要求.public function index else return this fetch qrcode u...

Thinkphp5 實現微信h5 支付

引入配置wxpay.config.php 就不多說了 order 付款資訊 bodys 付款內容 order number,money public function wxmobielpay 這兩個方法需要呼叫到 也要引入 設定請求方式 指定最多的http重定向的數量,這個選項是和curlopt f...

微信支付 微信JSAPI支付

pay.php baby extend wx pay.php namespace wx class pay 通過redirecturi獲取授權資訊 return mixed public function getauthinfo 通過code換取網頁授權資訊 res this curlgetreq ...