QrCodeOut.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * QrCodeOut.php UTF-8
  4. * 二维码对外
  5. *
  6. * @date : 2018/8/17 17:42
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huomp\controller\share;
  13. use huo\controller\common\Base;
  14. use huolib\status\AgentStatus;
  15. use huolib\status\CommonStatus;
  16. use huolib\status\OrderStatus;
  17. use huomp\controller\agent\AgentState;
  18. use huomp\controller\game\GameMini;
  19. use huoMpQr\QrCode;
  20. class QrCodeOut extends Base {
  21. /**
  22. * 获取小程序分享信息
  23. *
  24. * @param int $mem_id 玩家ID
  25. * @param int $app_id 应用ID
  26. *
  27. * @param string $path 分享路径
  28. * @param int $width
  29. * @param bool $auto_color
  30. * @param string $line_color
  31. * @param bool $is_hyaline
  32. *
  33. * @param int $ag_id 渠道游戏ID
  34. *
  35. * @return array
  36. */
  37. public function getQrCode(
  38. $mem_id, $app_id, $path, $width = 430, $auto_color = false, $line_color = '{"r":"0","g":"0","b":"0"}',
  39. $is_hyaline = false, $ag_id = 0
  40. ) {
  41. $_mpay_data = (new GameMini())->getLoginConf($app_id);
  42. $_mini_app_key = $_mpay_data['APP_KEY'];
  43. $_mini_app_secret = $_mpay_data['APP_SECRET'];
  44. if (empty($ag_id)) {
  45. $_scene = (new AgentState())->getCodeByMemApp($mem_id, $app_id);
  46. } else {
  47. $_scene = (new AgentState())->genAgentCode($ag_id);
  48. }
  49. $_image = (new QrCode())->getWxACodeUnLimit(
  50. $_mini_app_key, $_mini_app_secret, $path, $_scene, $width, $auto_color, $line_color, $is_hyaline
  51. );
  52. if (is_array($_image)) {
  53. $_code = CommonStatus::EXCEPTION;
  54. return $this->huoError($_code, AgentStatus::getMsg($_code), $_image);
  55. }
  56. $_rdata['image'] = $_image;
  57. $_code = CommonStatus::NO_ERROR;
  58. return $this->huoSuccess($_code, AgentStatus::getMsg($_code), $_rdata);
  59. }
  60. /**
  61. * 获取小程序订单信息
  62. *
  63. * @param string $order_id 订单ID
  64. * @param int $app_id 应用ID
  65. *
  66. * @param string $path 分享路径
  67. * @param $width
  68. * @param $auto_color
  69. * @param $line_color
  70. * @param $is_hyaline
  71. *
  72. * @return array
  73. */
  74. public function getOrderQrCode(
  75. $order_id, $app_id, $path, $width = 430, $auto_color = false, $line_color = '{"r":"0","g":"0","b":"0"}',
  76. $is_hyaline = false
  77. ) {
  78. if (empty($order_id)) {
  79. $_code = OrderStatus::ORDER_ID_EMPTY;
  80. return $this->huoError($_code, OrderStatus::getMsg($_code));
  81. }
  82. $_mpay_data = (new GameMini())->getLoginConf($app_id);
  83. $_mini_app_key = $_mpay_data['APP_KEY'];
  84. $_mini_app_secret = $_mpay_data['APP_SECRET'];
  85. $_image = (new QrCode())->getWxACodeUnLimit(
  86. $_mini_app_key, $_mini_app_secret, $path, $order_id, $width, $auto_color, $line_color, $is_hyaline
  87. );
  88. if (is_array($_image)) {
  89. $_code = CommonStatus::EXCEPTION;
  90. return $this->huoError($_code, AgentStatus::getMsg($_code), $_image);
  91. }
  92. $_rdata['image'] = $_image;
  93. $_code = CommonStatus::NO_ERROR;
  94. return $this->huoSuccess($_code, AgentStatus::getMsg($_code), $_rdata);
  95. }
  96. }