说的无益,看代码就行了 更多支付方式请到https://pay.yansongda.cn/docs/v2/
1. 微信H5支付
$config = [
'appid' => 'wxb3fxxxxxxxxxxx', // APP APPID
'app_id' => 'appid', // 公众号 APPID
'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
'mch_id' => 'merchant',
'key' => 'secretkey',
'notify_url' => 'wechatNotify',
'cert_client' => './cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到
'cert_key' => './cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到
'log' => [ // optional
'file' => LOG_PATH.'logs/wechat.log',
'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
'type' => 'single', // optional, 可选 daily.
'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
],
'http' => [ // optional
'timeout' => 5.0,
'connect_timeout' => 5.0,
// 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
],
// 'mode' => 'dev',
];
$order = [
'out_trade_no' => $number,
'body' => '支付测试',
'total_fee' => intval(0.01 * 100)
];
$pay = Pay::wechat($config)->wap($order); // (移动端H5支付)
return redirect($pay->getTargetUrl());exit; // 获取返回的链接直接跳转
2. 微信公众号支付
$config = [
'appid' => 'wxb3fxxxxxxxxxxx', // APP APPID
'app_id' => 'appid', // 公众号 APPID
'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
'mch_id' => 'merchant',
'key' => 'secretkey',
'notify_url' => 'wechatNotify',
'cert_client' => './cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到
'cert_key' => './cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到
'log' => [ // optional
'file' => LOG_PATH.'logs/wechat.log',
'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
'type' => 'single', // optional, 可选 daily.
'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
],
'http' => [ // optional
'timeout' => 5.0,
'connect_timeout' => 5.0,
// 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
],
// 'mode' => 'dev',
];
$order = [
'out_trade_no' => $number,
'body' => '充值支付',
'total_fee' => intval(0.01 * 100)
];
$order['openid'] = 'openid'; // 微信openid
$result = Pay::wechat($config)->mp($order);
$resData = [ //返回信息给前台 ,前台调起来微信支付
'appId' => $result->appId,
'timeStamp' => $result->timeStamp,
'nonceStr' => $result->nonceStr,
'package' => $result->package,
'signType' => $result->signType,
'paySign' => $result->paySign,
]; //{"appId":"wx","timeStamp":"16103","nonceStr":"oOSji","package":"prepay_id=wx085123","signType":"MD5","paySign":"589B82F"} 前端调用的格式
$jsApiParameters = json_encode($resData); // 转成功json格式页面直接调用即可
$this->assign('jsApiParameters', $jsApiParameters);
return $this->fetch(':wechatpay');
公众号支付需要页面调起,页面代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<title>微信安全支付</title>
<script type="text/javascript">
//调用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
{$jsApiParameters},
function(res){
// alert(res.err_code+res.err_desc+res.err_msg);
if(res.err_msg == "get_brand_wcpay_request:ok" ) {
window.location.href = "支付成功跳转";
} else if(res.err_msg == "get_brand_wcpay_request:fail" ) { //支付失
window.location.href = "失败跳转";
}
}
);
}
//function callpay()
window.onload = function ()
{
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
}
}else{
jsApiCall();
}
}
</script>
</head>
<body>
<?php if(!strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')){?>
<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>
<?php }?>
</body>
</html>