没有合适的资源?快使用搜索试试~ 我知道了~
首页基于thinkphp5框架实现微信小程序支付 退款 订单查询 退款查询操作
资源详情
资源评论
资源推荐

基于基于thinkphp5框架实现微信小程序支付框架实现微信小程序支付 退款退款 订单查询订单查询 退款查询操作退款查询操作
主要介绍了基于thinkphp5框架实现微信小程序支付 退款 订单查询 退款查询操作,本文通过实例代码给大家介绍的非常详
细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
微信小程序或微信支付相关操作支付退款订单查询退款查询支付成功,进行回调退款成功 进行回调用到的方法
支付
/**
* 预支付请求接口(POST)
* @param string $openid openid
* @param string $body 商品简单描述
* @param string $order_sn 订单编号
* @param string $total_fee 金额
* @return json的数据
*/
public function prepay()
{
tp_log('预支付请求数据===>' . json_encode($_POST), 'prepay', request()->controller());
$goods_user = db('tf_goods_user')->where(array('order_no' => $_POST['order_no']))->find();
$goods = db('tf_goods')->where(array('id' => $goods_user['goods_id']))->find();
//判断产品的数量
if (($goods['sales_initial'] - $goods['sales_actual']) <= 0) {
$return['status'] = 0;
$return['info'] = '此产品已售完';
exit(json_encode($return));
}
$order_no = $_POST['order_no']; //订单号
$is_sale = $_POST['is_sale'];
$openid = $_POST['openid'];
$goods_name = $_POST['goods_name'];
$pay_price = $_POST['price'];
$attach['is_sale'] = $_POST['is_sale'];
$attach['sale_id'] = $_POST['sale_id'];
$nonce_str = $this->nonce_str();//随机字符串
$order_no_ssh = $this->get_orderssh(); //商户订单号
//组装支付数据
$data = [
'appid' => config('pay.APPID'),
'mch_id' => config('pay.MCHID'),
'nonce_str' => $nonce_str,
'body' => $goods_name, //商品名称组合
'attach' => json_encode($attach),
'out_trade_no' => $order_no_ssh,//$order_no, //订单号 商户订单号
'total_fee' => intval($pay_price * 100),
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
'notify_url' => config('pay.NOTIFY_URL'),
'trade_type' => 'JSAPI',
'openid' => $openid
];
//订单支付表创建订单支付数据
$p_o_data['createtime'] = time();
$p_o_data['order_no'] = $order_no;
$p_o_data['order_no_ssh'] = $order_no_ssh;
$p_o_data['ready'] = json_encode($data);
$p_o_return = db('tf_pay_order')->insert($p_o_data);
if(!$p_o_return){
//失败
$return['status'] = -1;
$return['info'] = $p_o_data;
exit(json_encode($return));
}
// 获取签名
$sign = $this->makeSign($data);
$data['sign'] = $sign;
$xml = $this->toXml($data);
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; //发起支付接口链接
//发起预支付请求
$prepay_return_reslut_xml = $this->http_request($url, $xml);
$xml_to_arr = $this->fromXml($prepay_return_reslut_xml);
$return_result = json_encode($xml_to_arr, true);
tp_log('预支付请求返回数据array===>' .$return_result , 'prepay', request()->controller());
//记录预支付返回信息
db('tf_goods_order')->where(array('order_no' => $order_no))
->update(array(
'go_pay' => $return_result,
'updatetime' => time(),
'updateuser' => $openid
));
if($xml_to_arr['return_code'] == 'SUCCESS' && $xml_to_arr['result_code'] == 'SUCCESS'){
//成功
$time = time();

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0