EeasyWechat 微信app支付
用的是easywechat3.x版本 + php
use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order;
public function appPay()
{
if ($this->request->isPost()) {
$post = $this->request->post();
$result = [
'body' => '商品名称',
'out_trade_no' => ‘订单编号’,
'total_fee' => 10 * 100, // 金额
'spbill_create_ip' => '', // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
'notify_url' => '/notify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
];
$appOrder = new Order($result);
$appPayment = self::appPayment(); // 微信app配置信息 new Application(self::options);
$rest = $appPayment->payment->prepare($appOrder);
if ($rest->return_code != 'SUCCESS' || $rest->result_code != 'SUCCESS') {
$this->error('获取支付订单失败');
}
if ($rest->return_code == 'SUCCESS' && $rest->result_code == 'SUCCESS') {
$prepayId = $rest['prepay_id'];
$json = $appPayment->payment->configForAppPayment($prepayId);
$this->success('支付成功',$json);
} else {
$this->error('调起支付失败,稍后再试~');
}
}
$this->error('请求错误');
}