1. 程式人生 > >Thinkphp3.2.3引入外部類庫的函式vendor()

Thinkphp3.2.3引入外部類庫的函式vendor()

Thinkphp3.2.3引入外部類庫位置:Thinkphp/library/vendor/weixinpay---

當需要在控制器中引入該資料夾下的檔案的時候用函式vendor();

$class = str_replace(array('.', '#'), array('/', '.'), $class);
在vendor()函式中引入外部檔案的時候,用"."號代替"/",用"#"號代替"."

例如:

//生成二維碼
public function pay()
  {
//echo $_GET["name"];die;
//引入外部檔案
vendor("WeiXinPay.lib.WxPay#Api");
vendor
("WeiXinPay.example.WxPay#NativePay"); vendor("WeiXinPay.example.log"); $notify = new \NativePay(); $input = new \WxPayUnifiedOrder(); $input->SetBody("test"); $input->SetAttach("test"); $input->SetOut_trade_no(\WxPayConfig::MCHID.date("YmdHis")); $input->SetTotal_fee("1"); $input->SetTime_start
(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");//支付成功後的回撥地址 $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); $result = $notify->GetPayUrl($input
); $url2 = $result["code_url"]; //var_dump($url2);//null //var_dump($result); $this->assign("url2",$url2); $this->display("qrcode"); }