APP 微信支付 集成Think PHP

发布时间:2018-10-19 09:38:19 作者:Aoe Wide 阅读量:2892

/**
* APP微信支付
* @return [type] [description]
*/
public function wx_pay()
{
$params = request()->param();
$orderinfo = db('order')->where('id', $params['order_id'])->find();
$data['body'] = "商家名称";
$data['total_fee'] = $params['price']*100;
$data['out_trade_no'] = $orderinfo['order_sn'];
$data['notify_url'] = 'https://' . $_SERVER['HTTP_HOST'] . url('wxpay/wx_notify');
$pay = new Appwechat(config('wechat'));
$appParameters = $pay->createMchPay($data);
file_put_contents("pay.txt", json_encode($appParameters) . PHP_EOL, FILE_APPEND);

return json($appParameters);
}

/**
* APP微信回调
* @return [type] [description]
*/
public function wx_notify()
{
$pay = new Appwechat(config('wechat'));
$notify = $pay->getNotify();
if ($notify['code'] == 200) {
file_put_contents('wxpay.txt', '成功');
file_put_contents('wxpay.txt', json_encode($notify). PHP_EOL, FILE_APPEND);
$this->setOrderDevice($notify['data']['out_trade_no']);
} else {
file_put_contents('wxpay.txt', '失败');
}
}

下载地址:http://hljmdd.cn/download/Appwechat.zip

我要评论

Aoe WideAoe Wide   我要留言
Aoe Wide
Catfish(鲶鱼) Blog V 2.0.30