下载小程序支付demo
[https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11\_1](https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1)
```
<?php
namespace app\system\api;
use app\common\controller\Common;
use app\system\model\SystemUser as UserModel;
use app\system\model\SystemCooker as CookerModel;
use app\system\model\SystemOrder as OrderModel;
use app\system\model\SystemCat as CatModel;
use app\system\model\SystemGoods as GoodsModel;
use app\system\model\SystemRotation as RrotationModel;
use Env;
use hisi\Dir;
use think\Db as Db;
class Wxpay extends Common
{
/**
* 获取厨师个人信息
* @author 橘子俊 <364666827@qq.com>
* @return mixed
*/
public function index()
{
if(!empty($_GET['cooker_id'])) {
$data['data']['code'] = 0;
$data['data']['msg'] = CookerModel::where('id', '=', $_GET['cooker_id'])->select();
}else{
$data['data']['code'] = 1;
$data['data']['msg'] = '用户id不能为空';
}
echo json_encode($data);exit;
}
/*
* 去支付
* @return int
* @throws \WxPayException
*/
public function wxpay(){
// $orderNum = time().rand(10000,99999);
if(!empty($_GET['user_id'])){
$userinfo = Db::table('hisi_system_cooker') -> where(['id'=>$_GET['user_id']]) -> find();
}
if(!empty($_GET['order_id'])){
$orderInfo = Db::table('hisi_system_goods_order') -> where(['id'=>$_GET['order_id']]) -> find();
}else{
exit;
}
// $openid = "oIR-q5c-oYEfvhxj8IhY8DtD7kcA";
$openid = $userinfo['open_id'];
$money = $orderInfo['total_price']*100;// 订单总金额,单位为分,详见支付金额
// $money = 1000;// 订单总金额,单位为分,详见支付金额
require_once '../extend/wxpay/lib/WxPay.Api.php';//引用类文件
require_once '../extend/wxpay/example/WxPay.Config.php';//引用类文件
require_once '../extend/wxpay/example/WxPay.JsApiPay.php';//引用类文件
//②、统一下单
$tools = new \JsApiPay();
$input = new \WxPayUnifiedOrder();
$input->SetBody("微信支付"); //这里是支付内容
$input->SetAttach('test'); //此处可传值,待支付成功后可取这部分的值
$input->SetOut_trade_no($orderInfo['order_no']); //订单编号
$input->SetTotal_fee($money); //金额
// $input->SetTotal_fee(1); //金额
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
// $input->SetNotify_url("http://ceshi.net/Retailapi/Weixinpay/notify");//回调地址
$input->SetNotify_url("https://chushi.yongtantec.com//api.php/system/wxpay/Wxpay/notify");//回调地址
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openid);
$config = new \WxPayConfig();
$order = \WxPayApi::unifiedOrder($config, $input);
$jsApiParameters = $tools->GetJsApiParameters($order);
$data['res'] = $jsApiParameters;
echo json_encode($data);
}
/*
*回调地址
*/
public function notify(){
//获取返回的xml
$testxml = file_get_contents("php://input");
//将xml转化为json格式
$jsonxml = json_encode(simplexml_load_string($testxml, 'SimpleXMLElement', LIBXML_NOCDATA));
//转成数组
$result = json_decode($jsonxml,true);
// $myfile = fopen("a.txt", "w") or die("Unable to open file!");
// fwrite($myfile, $jsonxml);
// fclose($myfile);
// file_put_contents('a.txt',$jsonxml); // --这里是调试方法根目录中test.txt中可查看数据情况
if($result){
//如果成功返回了
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
file_put_contents('test.txt',$result);
$orderSn = $result['out_trade_no'];
$transactionId = $result['transaction_id'];
$orderIni['order_num'] = $orderSn;
$res = Db::table('hisi_system_goods_order')->where(['order_no'=>$orderSn])->find();//查询订单
$userinfo = Db::table('hisi_system_cooker')->where(['id'=>$res['cooker_id']])->find();//查询用户信息
if($res['status'] != 1){
$orderData['transaction_id'] = $transactionId;
$res['status'] = 4;
$orderData['end_time'] = time();
// $userinfo['balance'] = $userinfo['balance'] + $result['total_fee']/100;
Db::table('hisi_system_goods_order')->where(['order_no'=>$orderSn])->save($res);
Db::table('hisi_system_cooker')->where(['id'=>$res['user_id']])->save($userinfo);
}
echo exit('<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>');
}
}
}
}
```
- tp5图片上传
- 文件上传到七牛云
- 上传到阿里云
- 富文本编辑器
- phpexcel和spreadsheet
- phpexcel导出
- phpexcel导入
- spreadsheet
- tp5_api接口
- 跨域请求
- JWT
- 图片和视频上传接口
- 验证码
- tp5小程序登录
- tp5小程序支付
- tp5基础架构
- 验证层
- 模型层Model
- 控制器构找
- tp5.0支付宝
- 海报二维码
- 轮播图
- echarts柱状图
- layui的图片弹窗
- p标签显示指定行数(全部)
- jquery和layerdate调用日期
- ajax发送文件和图片的坑啊
- JS日期点击上一天和下一天
- 百度分享js
- POST请求
- 商品数据表
- tp5.0支付宝最全
- tp5路由的坑
- 二维数组排序
- tp5模型分组group错误
- 二维变一维数组
- 无限树形结构
- json对象转数组
- 模型关联查询
- tp5的模型获取器和字段设定
- 经纬度获取距离排序