微信支付 h5支付 已经测通

浏览:6097 发布日期:2017/10/24 分类:业务逻辑 关键字: 微信支付 h5支付
微信支付 h5支付
首先在 定义 在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;





$xml = $this->arrayToxml($data);
$response = $this->postxmlCurl($xml, $url);



//将微信返回的结果xml转成数组
$response = $this->xmlToArray($response);





//请求数据,统一下单

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>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>微信安全支付</title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
</br></br></br></br>
<div align="center">
<!-- <button style="width:210px; height:30px; background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" >贡献一下</button> -->

<h1> <a href="{$res.mweb_url}">微信支付</a></h1>
</div>
</body>
</html>

有问题请加微信h5支付群 649500623
评论( 相关
后面还有条评论,点击查看>>