当前位置: 首页 > news >正文

微信支付开发-前端api实现

一、操作流程图

二、代码实现

<?php
/*** 数字人答题业务流* User: 龙哥·三年风水* Date: 2024/9/11* Time: 14:59*/
namespace app\controller\shuziren;
use app\controller\Base;
use app\model\param\QuestionParam as PQPModel;
use app\model\answer\QuestionBank;
use app\model\answer\QuestionOpt;
use app\model\answer\StatisticsAnswer;
use app\service\WechatPayNative;
use Redis\Redis;
use app\model\answer\QuestionPrize;
use app\model\answer\QuestionOrder;
use Rabbit\order\Delayed\Pro;
class Answer extends Base
{// 获取答题public function index(){$questParam = PQPModel::dataFind(['id' => 1],'answer_number,answer_accuracy');$allList = QuestionBank::getAll(['status' => 1],'id','create_time DESC');if(count($allList) < $questParam['answer_number'])return error('题目数量不够');$answerArr = array_rand(array_column($allList,'id'),$questParam['answer_number']);$answerList = [];foreach($answerArr as $k => $v){$answerList[$k]['id'] = $k + 1;$answerList[$k]['title'] = QuestionBank::dataFind(['id' => $v],'title',false);$answerList[$k]['opt'] = QuestionOpt::getAll(['bank_id' => $v],'opt,content,is_correct','id ASC');}$data['list'] = $answerList;$data['answer_accuracy'] = $questParam['answer_accuracy'];return success($data);}// 记录答题public function statistics(){$param = $this->request->param();$validate = new \app\validate\answer\StatisticsAnswer;if (!$validate->check($param))return error($validate->getError());//验证参数$questParam = PQPModel::dataFind(['id' => 1],'answer_number,answer_interval_period');if(($param['correct_rate'] + $param['error_rate']) != $questParam['answer_number'])return error('非法操作');//验证参数$data['digitized_human_id'] = $this->token;$data['digitized_human_name'] = $param['digitized_human_name'];$data['correct_rate'] = $param['correct_rate'];$data['error_rate'] = $param['error_rate'];$data['id_card'] = $param['id_card'];$data['involved_date'] = date('Y-m-d',time());$data['status'] = 1;$data['create_time'] = date('Y-m-d H:i:s',time());$data['update_time'] = date('Y-m-d H:i:s',time());StatisticsAnswer::save($data,[]);$res = [];if((int)$questParam['answer_interval_period'] > 0){$redis = Redis::select(config('cache.stores.redis.other_db'));$keyLog = 'answer_'.$param['id_card'];$answerLog = $redis->get($keyLog);if(empty($answerLog)){$redis->setex($keyLog,(int)$questParam['answer_interval_period']*24*3600,1);$res['receive_prize'] = 0;$res['order_no'] = create_order();}else{$res['receive_prize'] = $redis->ttl($keyLog);$res['order_no'] = '';}}return success($res);}// 获取奖品public function prize(){$idCard = $this->request->param('id_card','');if(empty($idCard))return error('参数错误');$redis = Redis::select(config('cache.stores.redis.other_db'));$keyLog = 'answer_'.$idCard;$answerLog = $redis->get($keyLog);if(empty($answerLog))return error('非法访问');$data = QuestionPrize::dataFind(['id' => 1,'status' => 1],'id,prize_name,prize_price,postage_price,prize_picture',true);return success($data);}// 创建订单public function order(){$param = $this->request->param();$validate = new \app\validate\answer\QuestionOrder;if(!$validate->check($param))return error($validate->getError());//验证参数$redis = Redis::select(config('cache.stores.redis.other_db'));$keyLog = 'answer_'.$param['id_card'];$answerLog = $redis->get($keyLog);if(empty($answerLog))return error('非法访问');$prizeName = QuestionPrize::dataFind(['id' => $param['prize_id'],'status' => 1],'prize_name',false);if(empty($prizeName))return error('奖品走丢咯~~~~~');$data['digitized_human_id'] = $this->token;$data['order_no'] = $param['order_no'];$data['consignee_name'] = $param['consignee_name'];$data['consignee_phone'] = $param['consignee_phone'];$data['prize_name'] = $prizeName;$data['area'] = $param['area'];$data['details_addr'] = $param['details_addr'];$data['id_card'] = $param['id_card'];$data['receipt_status'] = 1;$data['express_company'] = '';$data['express_number'] = '';$data['status'] = 1;$data['create_time'] = date('Y-m-d H:i:s',time());$data['update_time'] = date('Y-m-d H:i:s',time());$res = QuestionOrder::save($data,[]);Pro::pushSend($res,20*60);return success([],'操作成功');}//获取支付二维码public function orderPayment(){$orderNo = $this->request->param('order_no');if(empty($orderNo))return error('参数错误');$receiptStatus = QuestionOrder::dataFind(['order_no' => $orderNo],'receipt_status',false);if($receiptStatus != 1)return error('没有未支付订单');$postagePrice = QuestionPrize::dataFind(['id' => 1,'status' => 1],'postage_price',false);$res = [];if($postagePrice > 0){$postagePrice = 0.01;$nativeService = new WechatPayNative();$res = $nativeService->pay_payment($orderNo,$postagePrice);}return success($res,'操作成功');}//获取支付结果public function orderPaymentResult(){$orderNo = $this->request->param('order_no');if(empty($orderNo))return error('参数错误');$receiptStatus = QuestionOrder::dataFind(['order_no' => $orderNo],'receipt_status',false);return success(['receipt_status' => empty($receiptStatus) ? 0 : $receiptStatus],'操作成功');}//重新生成订单号public function answerOrderRepeat(){$orderNo = $this->request->param('order_no');if(empty($orderNo))return error('参数错误');$res = QuestionOrder::dataFind(['order_no' => $orderNo],'id,receipt_status',true);if(!empty($res)){if($res['receipt_status'] == 4){$orderNo = create_order();QuestionOrder::save(['order_no' =>  $orderNo,'receipt_status'   =>  1],['id'    =>  $res['id']]);Pro::pushSend($res['id'],20*60);}}return success(['order_no' =>  $orderNo]);}
}

http://www.mrgr.cn/news/28985.html

相关文章:

  • 星绘AI 0.8.9 | 免费的AI绘画写真滤镜穿搭软件
  • 数据结构——快速排序
  • 探索美赛:从准备到挑战的详细指南
  • 雷池waf安装并部署防护站点
  • 安科瑞工业绝缘监测装置:保障煤矿井下6kV供电系统安全运行的关键应用——安科瑞 丁佳雯
  • Spring Boot 接口防重复提交解决方案
  • 系统架构设计师 大数据架构篇二
  • Spring 源码解读:实现@Scope与自定义作用域
  • hnust 湖科大 毕业实习常见问题30问(2021 年7月,V0.9)
  • 基于TCP实现聊天
  • grep 命令:文本搜索
  • Qt优秀开源项目之二十三:QSimpleUpdater
  • Vert.x初探
  • 星火AI图片理解API文档
  • claude,gpt,通义千问
  • 人工智能与机器学习原理精解【20】
  • 探索 InternLM 模型能力边界
  • OpenAI API key not working in my React App
  • 稠密向量检索、稀疏向量检索、BM25检索三者对比
  • 获取Live2d模型
  • 办了房屋抵押经营贷,空壳公司不怕被查吗?续贷不上怎么办?
  • stella_vslam
  • 神经网络-MNIST数据集训练
  • Typora安装,使用,图片加载全流程!!!
  • BUUCTF逆向wp [WUSTCTF2020]level3
  • 从函数的角度理解运算