callback.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. use App\Oauth\YlyOauthClient;
  3. use App\Api\PrintService;
  4. use App\Api\PicturePrintService;
  5. use App\Api\ExpressPrintService;
  6. $client = new YlyOauthClient($config);
  7. try {
  8. $token = $client->getToken();
  9. } catch (Exception $e) {
  10. echo $e->getMessage() . "\n";
  11. print_r(json_decode($e->getMessage(), true));
  12. return;
  13. }
  14. $access_token = $token->access_token; //调用API凭证AccessToken 永久有效,请妥善保存.
  15. $refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天
  16. $expires_in = $token->expires_in; //自有型应用可忽略此回调参数, AccessToken失效时间30天
  17. $machine_code = ''; //机器码
  18. $origin_id = ''; //内部订单号(32位以内)
  19. /**文本接口开始**/
  20. $print = new PrintService($access_token, $config);
  21. //58mm排版 排版指令详情请看 http://doc2.10ss.net/332006
  22. $content = "<FS2><center>**#1 美团**</center></FS2>";
  23. $content .= str_repeat('.', 32);
  24. $content .= "<FS2><center>--在线支付--</center></FS2>";
  25. $content .= "<FS><center>张周兄弟烧烤</center></FS>";
  26. $content .= "订单时间:". date("Y-m-d H:i") . "\n";
  27. $content .= "订单编号:40807050607030\n";
  28. $content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14);
  29. $content .= "<table>";
  30. $content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>";
  31. $content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>";
  32. $content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>";
  33. $content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>";
  34. $content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>";
  35. $content .= "</table>";
  36. $content .= str_repeat('.', 32);
  37. $content .= "<QR>这是二维码内容</QR>";
  38. $content .= "小计:¥82\n";
  39. $content .= "折扣:¥4 \n";
  40. $content .= str_repeat('*', 32);
  41. $content .= "订单总价:¥78 \n";
  42. $content .= "<FS2><center>**#1 完**</center></FS2>";
  43. try{
  44. var_dump($print->index($machine_code, $content, $origin_id));
  45. }catch (Exception $e) {
  46. echo $e->getMessage();
  47. }
  48. /**文本接口结束**/
  49. ///**图形接口开始**/
  50. //$picturePrint = new PicturePrintService($access_token, $config);
  51. //$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg";
  52. //try{
  53. // var_dump($picturePrint->index($machine_code, $content, $origin_id));
  54. //}catch (Exception $e) {
  55. // echo $e->getMessage();
  56. //}
  57. ///**图形接口结束**/
  58. ///**面单接口开始**/ //打印机型必须为k5;
  59. //$expressPrint = new ExpressPrintService($access_token, $config);
  60. //$content = array(
  61. // "OrderCode"=> "0126578665784971",
  62. // "ShipperCode"=> "SF", //SF YZPY HTKY YD
  63. // "PayType"=> 1,
  64. // "ExpType"=> 1,
  65. // "Cost"=>6.0,
  66. // "OtherCost"=> 7.0,
  67. // "CustomerName" => '1264546',
  68. // "CustomerPwd" => '4545454',
  69. // "MonthCode" => '',
  70. // "Sender"=> array(
  71. // "Company" => "5645645",
  72. // "Name" => "Taylor",
  73. // "Mobile" => "15018442396",
  74. // "ProvinceName" => "上海",
  75. // "CityName" => "上海",
  76. // "PostCode" => '61000',
  77. // "ExpAreaName" => "青浦区",
  78. // "Address" => "明珠路73号"
  79. // ),
  80. // "Receiver"=> array(
  81. // "Company"=> "789789",
  82. // "Name"=> "Yann",
  83. // "Mobile"=> "15018442396",
  84. // "ProvinceName"=> "北京",
  85. // "CityName"=> "北京",
  86. // "PostCode" => '61000',
  87. // "ExpAreaName"=> "朝阳区",
  88. // "Address"=> "三里屯街道雅秀大厦"
  89. // ),
  90. // "Commodity" => array(
  91. // array(
  92. // "GoodsName"=> "鞋子",
  93. // )
  94. // ),
  95. // "AddService"=> array(
  96. // array(
  97. // "Name"=> "COD",
  98. // "Value"=> "1020",
  99. // "CustomerID" => "44564"
  100. // )
  101. // ),
  102. // "StartDate" => date("y-M-d H:i:s",time() + 7200),
  103. // "Weight"=> 1.0,
  104. // "Quantity"=> 1,
  105. // "Volume"=> 0.0,
  106. // "Remark"=> "小心轻放",
  107. //);
  108. //
  109. //try{
  110. // var_dump($expressPrint->index($machine_code, $content, $origin_id));
  111. //}catch (Exception $e) {
  112. // echo $e->getMessage();
  113. //}
  114. ///**面单接口结束**/