/**
* 微信支付
*/
public function pay()
{
$amount = floatval(config("site.jiage"));
$type = $this->request->post('type',"wechat");
$method = $this->request->post('method',"web"); //web如果是公众号会自动识别跳转到epay/api有现成模板
$openid = $this->request->post('openid', "");
if (!$amount || $amount < 0) {
$this->error("支付金额必须大于0");
}
if (!$type || !in_array($type, ['alipay', 'wechat'])) {
$this->error("支付类型不能为空");
}
if (in_array($method, ['miniapp', 'mp']) && !$openid) {
$this->error("openid不能为空");
}
//订单号
$out_trade_no = date("YmdHis") . mt_rand(1000, 9999);
//订单标题
$title = '测试订单';
//回调链接
$notifyurl = $this->request->root(true) . '/addons/epay/index/notifyx/paytype/' . $type;
$returnurl = $this->request->root(true) . '/addons/epay/index/returnx/paytype/' . $type . '/out_trade_no/' . $out_trade_no;
$response = \addons\epay\library\Service::submitOrder($amount, $out_trade_no, $type, $title, $notifyurl, $returnurl, $method, $openid);
return $response;
}
快捷键:weixinzhifu
源:
sublime_text格式
<snippet>
<content><![CDATA[
/**
* 微信支付
*/
public function pay()
{
\$amount = floatval(config("site.jiage"));
\$type = \$this->request->post('type',"wechat");
\$method = \$this->request->post('method',"web"); //web如果是公众号会自动识别跳转到epay/api有现成模板
\$openid = \$this->request->post('openid', "");
if (!\$amount || \$amount < 0) {
\$this->error("支付金额必须大于0");
}
if (!\$type || !in_array(\$type, ['alipay', 'wechat'])) {
\$this->error("支付类型不能为空");
}
if (in_array(\$method, ['miniapp', 'mp']) && !\$openid) {
\$this->error("openid不能为空");
}
//订单号
\$out_trade_no = date("YmdHis") . mt_rand(1000, 9999);
//订单标题
\$title = '测试订单';
//回调链接
\$notifyurl = \$this->request->root(true) . '/addons/epay/index/notifyx/paytype/' . \$type;
\$returnurl = \$this->request->root(true) . '/addons/epay/index/returnx/paytype/' . \$type . '/out_trade_no/' . \$out_trade_no;
\$response = \addons\epay\library\Service::submitOrder(\$amount, \$out_trade_no, \$type, \$title, \$notifyurl, \$returnurl, \$method, \$openid);
return \$response;
}
]]></content>
<tabTrigger>weixinzhifu(微信支付简单版)</tabTrigger>
<scope></scope>
</snippet>
发表评论 取消回复