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

ThinkPHP对接易联云打印

引入composer包

composer require yly-openapi/yly-openapi-sdk

<?phpnamespace app\common\library;use app\admin\model\yp\Order;
use App\Api\PrintService;
use App\Config\YlyConfig;
use App\Oauth\YlyOauthClient;
use think\Cache;
use think\Config;class Yly
{/*** 易联云打印订单* @param $security_info* @return int* @throws \think\Exception*/public function print_yly($security_info){//获取配置中的应用id和密匙$config = new YlyConfig(Config::get('site.clientId'), Config::get('site.clientSecret'));$client = new YlyOauthClient($config);try {$token = Cache::get('access_token');if ($token) {$token = json_decode($token);}if (!$token) {$token = $client->getToken();Cache::set('access_token', json_encode($token), 864000);}} catch (Exception $e) {throw new \think\Exception('获取或更新access_token的次数,已超过最大限制! ');echo $e->getMessage() . "\n";print_r(json_decode($e->getMessage(), true));return;}$access_token = $token->access_token;           //调用API凭证AccessToken 永久有效,请妥善保存.$refresh_token = $token->refresh_token;         //刷新AccessToken凭证 失效时间35天$expires_in = $token->expires_in;               //自有型应用可忽略此回调参数, AccessToken失效时间30天         //机器码$origin_id = time();                                //内部订单号(32位以内)/**文本接口开始**/$print = new PrintService($access_token, $config);//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006$content = '';//$content .= "<FS2><center>金蛋到家</center></FS2>";$content .= "时间:".date('Y-m-d H:i:s', $security_info->createtime) . "\n";$content .= "单号:". $security_info->order_no . "\n";$content .= "姓名:". $security_info->name . "\n";$content .= "电话:". $security_info->phone . "\n";$content .= "城市:". $security_info->city . "\n";$content .= "地址:". $security_info->address . "\n";$content .= "商品:------------". "\n";foreach ($security_info->item as $key=>$value){$content .= $value['goods_title']."*".$value['num']."\n";}$content .= "-----------------". "\n";$content .= "备注:". $security_info->remarks . "\n";$content .= "金额:". $security_info->goods_money . "\n";$youhui = $security_info->goods_money-$security_info->actual_money;if($youhui >0){$content .= "优惠:". $youhui . "\n";}$content .= "实付:". $security_info->actual_money . "\n";try {//获取配置中的设备号$res = $print->index(Config::get('site.machineCode'), $content, $origin_id);} catch (Exception $e) {throw new \think\Exception('打印失败');return 0;}//打印状态升级成已打印Order::where('id',$security_info->id)->where('print_status','0')->update(['print_status'=>'1']);return 1;}}

如上,传入一个订单信息,根据订单信息定义打印文本

易联云文档:指令集 · yilianyun-open-api · 看云

http://www.lryc.cn/news/406698.html

相关文章:

  • JavaScript轮播图
  • 修复SteamUI.dll加载失败的指南,快速修复failed to load steamui.dll
  • PCL Local Surface Patches 关键点提取
  • Vue与ASP.NET Core Web Api设置localhost与本地ip地址皆可访问
  • Android 线程池的面试题 线程线程池面试题
  • Flink时间和窗口
  • LLaMA模型量化方法优化:提高性能与减小模型大小
  • 前端CSS实现卡片抽奖效果
  • Java在for循环中修改集合
  • Java小白入门到实战应用教程-运算符详解
  • secureCRT同时在所有已打开窗口执行命令、mac-os下使用的SecureCRT版本 以及 SecureCRT一段时间不操作没有响应的问题
  • 增材制造与智能制造关系
  • Google Test 学习笔记(简称GTest)
  • 不可变集合
  • 景区AR导航营销系统:技术解决方案与实施效益分析
  • MATLAB的基础知识
  • Redis-高级实战案例
  • d3d12.dll 文件缺失如何解决?五种修复丢失问题的方法
  • Linux下如何设置系统定时任务
  • 【React】JSX 实现列表渲染
  • 写一个简单的兼容GET/POST请求的登录接口
  • 【好玩的经典游戏】Docker环境下部署赛车小游戏
  • 物理机 gogs+jenkins+sonarqube 实现CI/CD
  • 前端表格解析方法
  • Leetcode 3227. Vowels Game in a String
  • 树莓派4B从装系统raspbian到vscode远程编程(python)
  • vue上传Excel文件并直接点击文件列表进行预览
  • OpenCV 像素操作—证件照换底色详细原理 C++纯手写实现
  • tinygrad框架简介;MLX框架简介
  • 服务器重启了之后就卡在某个页面了,花屏,如何解决??