首先在 定义 在config.php 中定义
'wxpay' => [
'appid' =>'xxxxxxxx',
'mch_id' =>'xxxxxxxx',
'key' =>'xxxxxxxx',
'appsecret'=>'xxxxxxxx',
],
这是model中定义的类
public function payh5($openid,$total_fee,$body,$out_trade_no){
$config= config('wxpay');
$ip= request()->ip();
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
$notify_url ='http://'.$_SERVER['HTTP_HOST'].'/index/index/notify';
$onoce_str = $this->createNoncestr();
$data["appid"] = $config['appid'];
$data["body"] = $body;
$data["mch_id"] = $config['mch_id'];
$data["nonce_str"] = $onoce_str;
$data["notify_url"] = $notify_url;
$data["out_trade_no"] = $out_trade_no;
$data["spbill_create_ip"] = $ip;
$data["total_fee"] = $total_fee;
$data["trade_type"] = "MWEB";
$data["scene_info"] = "{'h5_info': {'type':'Wap','wap_url': $notify_url,'wap_name': '测试充值'}}";
$sign = $this->getSign($data);
// halt($data);
$data["sign"] = $sign;
$xm
$response = $this->postxm
//将微信返回的结果xm
$response = $this->xm
//请求数据,统一下单
return $response;
}
controller 中调用model
public function h5pay(){
//openid不用传没啥用
$Weixin_payh5=new Weixin_payh5();
$openid="";
$total_fee=1;
$body="wamp支付测试";
$order_sn=time();
$res=$Weixin_payh5->payh5($openid,$total_fee,$body,$order_sn);
$this->assign("res",$res);
return $this->fetch("h5");
}
view 中的代码
<html>
<head>
<me
<ti
<me
</head>
<body>
</br></br></br></br>
<div align="center">
<!-- <button st
<h1> <a href="{$res.mweb_url}">微信支付</a></h1>
</div>
</body>
</html>
有问题请加微信h5支付群 649500623
