H5是移动网页应用的重要形态,具有跨平台、免安装、易传播的特点。本文档描述了H5渠道的完整配置流程。
h5
// 渠道基本信息
'channel' => 'h5',
'name' => 'H5',
'status' => true, // 开启/关闭
'description' => 'H5移动网页应用平台接入'
'h5_config' => [
'domain' => 'https://h5.yourdomain.com',
'cdn_domain' => 'https://cdn.yourdomain.com',
'ssl_enabled' => true,
'cache_config' => [
'enable' => true,
'expire' => 3600, // 缓存过期时间
],
'seo_config' => [
'title' => '应用标题',
'keywords' => '关键词',
'description' => '应用描述'
]
]
H5支持以下支付方式:
'payment_config' => [
'wechat' => [
'enabled' => true,
'app_id' => '微信公众号AppID',
'mch_id' => '商户号',
'key' => '商户密钥',
'cert_path' => '证书路径',
'notify_url' => '支付回调地址',
'scene_info' => [
'h5_info' => [
'type' => 'Wap',
'wap_url' => 'https://h5.yourdomain.com',
'wap_name' => 'H5应用'
]
]
]
]
'payment_config' => [
'alipay' => [
'enabled' => true,
'app_id' => '支付宝应用ID',
'private_key' => '应用私钥',
'public_key' => '支付宝公钥',
'notify_url' => '支付回调地址',
'return_url' => '支付返回地址'
]
]
'payment_config' => [
'balance' => [
'enabled' => true,
'min_amount' => 0.01, // 最小支付金额
'max_amount' => 50000, // 最大支付金额
]
]
'login_config' => [
'auto_login' => false, // H5通常不建议自动登录
'auto_register' => true,
]
'login_config' => [
'force_mobile' => true,
'mobile_verify' => true, // 手机号验证
]
'login_config' => [
'wechat_login' => [
'enabled' => true,
'app_id' => '微信开放平台AppID',
'app_secret' => '微信开放平台AppSecret',
'scope' => 'snsapi_login'
],
'qq_login' => [
'enabled' => true,
'app_id' => 'QQ互联AppID',
'app_key' => 'QQ互联AppKey'
]
]
功能 | 支持状态 | 说明 |
---|---|---|
支付功能 | ✅ | 支持微信支付、支付宝支付、余额支付 |
分享功能 | ✅ | 支持分享到各种平台 |
定位功能 | ✅ | 支持获取用户地理位置 |
拍照功能 | ✅ | 支持调用摄像头拍照 |
推送功能 | ❌ | 不支持推送通知 |
域名配置
服务器配置
CDN配置(可选)
基本信息配置
渠道状态: 开启
渠道名称: H5
渠道描述: H5移动网页应用平台
平台参数配置
域名: https://h5.yourdomain.com
CDN域名: https://cdn.yourdomain.com
SSL状态: 开启
支付方式配置
微信支付: 开启
支付宝支付: 开启
余额支付: 开启
货到付款: 关闭
登录方式配置
自动登录: 关闭
绑定手机号: 开启
微信登录: 开启
QQ登录: 开启
前端代码配置
// config.js
const config = {
apiUrl: 'https://api.yourdomain.com',
cdnUrl: 'https://cdn.yourdomain.com',
channel: 'h5',
payment: {
wechat: true,
alipay: true,
balance: true
}
};
javascript
// 微信登录
function loginWithWechat() {
const redirectUri = encodeURIComponent(window.location.href);
const authUrl =
https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`;
window.location.href = authUrl; } ```
支付调用
// 微信支付
function payWithWechat(orderInfo) {
if (typeof WeixinJSBridge === 'undefined') {
alert('请在微信中打开');
return;
}
WeixinJSBridge.invoke('getBrandWCPayRequest', {
appId: orderInfo.appId,
timeStamp: orderInfo.timeStamp,
nonceStr: orderInfo.nonceStr,
package: orderInfo.package,
signType: orderInfo.signType,
paySign: orderInfo.paySign
}, function(res) {
if (res.err_msg == 'get_brand_wcpay_request:ok') {
// 支付成功
}
});
}
# 测试登录接口
curl -X POST "https://api.yourdomain.com/api/login" \
-H "Content-Type: application/json" \
-d '{"code":"授权code","channel":"h5"}'
# 测试支付接口
curl -X POST "https://api.yourdomain.com/api/payment/create" \
-H "Content-Type: application/json" \
-d '{"amount":100,"channel":"h5","payment_type":"wechat"}'
移动适配
性能优化
SEO优化
安全配置
A: 需要配置微信JSSDK,使用WeixinJSBridge调用支付接口。
A: 检查return_url配置,确保返回地址可访问。
A: 使用CDN、压缩资源、优化图片、开启Gzip压缩。
A: 配置CORS头部,或使用代理服务器。