TestController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantService;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\message\classes\InformAdminClass;
  7. use bizHd\message\services\InformAdminService;
  8. use bizHd\order\services\OrderService;
  9. use bizHd\wx\classes\WxOpenClass;
  10. use bizGhs\express\services\MiniExpressService;
  11. use bizGhs\product\classes\ProductClass;
  12. use common\components\baiduAip;
  13. use common\components\barcodeUtil;
  14. use common\components\lakala\Lakala;
  15. use common\components\miniUtil;
  16. use common\components\orderSn;
  17. use common\components\oss;
  18. use common\components\wxUtil;
  19. use Yii;
  20. use common\components\util;
  21. class TestController extends BaseController
  22. {
  23. public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
  24. public function actionAliRun()
  25. {
  26. // $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/cs_private_key.pem';
  27. // $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/cs_cert.cer';
  28. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  29. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/api_cert.cer';
  30. $params = [
  31. 'appid' => 'OP00002119',
  32. 'serial_no' => '018b08cfddbd',
  33. 'merchant_no' => '8224050539900TF',
  34. 'term_no' => 'C7632663',
  35. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  36. 'lklCertificatePath' => $lklCertificatePath,
  37. ];
  38. $laResource = new Lakala($params);
  39. $outTradeNo = orderSn::getPurchaseSn();
  40. $price = 0.1;
  41. $response = $laResource->driveAliPay($outTradeNo, $price);
  42. print_r($response);die;
  43. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  44. echo '<pre>';
  45. echo "下单成功<br/>";
  46. print_r($response);
  47. } else {
  48. echo '<pre>';
  49. echo "下单失败<br/>";
  50. print_r($response);
  51. }
  52. }
  53. public function actionRun()
  54. {
  55. // $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/cs_private_key.pem';
  56. // $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/cs_cert.cer';
  57. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  58. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/api_cert.cer';
  59. $params = [
  60. 'appid' => 'OP00002119',
  61. 'serial_no' => '018b08cfddbd',
  62. 'merchant_no' => '8224050539900TF',
  63. 'term_no' => 'C7632663',
  64. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  65. 'lklCertificatePath' => $lklCertificatePath,
  66. ];
  67. $laResource = new Lakala($params);
  68. $outTradeNo = orderSn::getPurchaseSn();
  69. $price = 0.1;
  70. $response = $laResource->driveWxPay($outTradeNo, $price);
  71. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  72. echo '<pre>';
  73. echo "下单成功<br/>";
  74. print_r($response);
  75. } else {
  76. echo '<pre>';
  77. echo "下单失败<br/>";
  78. print_r($response);
  79. }
  80. }
  81. public function actionIndex()
  82. {
  83. //header('Content-type:image/png');
  84. $productId = 1;
  85. $barcode = barcodeUtil::barcodeGeneratorPNG($productId);
  86. oss::uploadContent("ghs/barcode/" . $productId . '.png', $barcode);
  87. $barcode = base64_encode($barcode);
  88. echo ' <img src="data:image/png;base64,' . $barcode . '"/>';
  89. // $merchantExtend = WxOpenClass::getGhsWxInfo();
  90. // // $res = baiduAip::transfer("你好");
  91. // dd($merchantExtend);
  92. }
  93. //dada 城市code
  94. public function actionDadaCityCode()
  95. {
  96. $res = dada::getCityCode(0);
  97. util::success($res);
  98. }
  99. //理由
  100. public function actionDadaReasons()
  101. {
  102. $res = dada::getCancelReason(0);
  103. util::success($res);
  104. }
  105. //达达 :下单
  106. public function actionDadaAddOrder()
  107. {
  108. $orderSn = 'XSD_CS26316851';
  109. $orderInfo = OrderClass::getByOrderSn($orderSn);
  110. $res = DadaExpressServices::addOrder($orderInfo);
  111. util::success($res);
  112. }
  113. //重发快递
  114. public function actionDadaReAdd()
  115. {
  116. $orderSn = 'XSD_CS26316851';
  117. $orderInfo = OrderClass::getByOrderSn($orderSn);
  118. $res = DadaExpressServices::reAddOrder($orderInfo);
  119. util::success($res);
  120. }
  121. //达达状态查询
  122. public function actionDadaOrderStatus()
  123. {
  124. $orderSn = 'XSD_CS26316851';
  125. $res = DadaExpressServices::statusOrder($orderSn);
  126. util::success($res);
  127. }
  128. //达达取消下单
  129. public function actionDadaCancelOrder()
  130. {
  131. $orderSn = 'XSD_CS26316851';
  132. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  133. util::success($res);
  134. }
  135. //获取已支持的配送公司列表接口
  136. public function actionGetAllDelivery()
  137. {
  138. $data = MiniExpressService::getAllImmeDelivery();
  139. util::success($data);
  140. }
  141. //即时配送
  142. /*
  143. * Array
  144. (
  145. [resultcode] => 0
  146. [resultmsg] => OK
  147. [shop_list] => Array
  148. (
  149. [0] => Array
  150. (
  151. [shopid] => 1588714266
  152. [delivery_id] => SFTC
  153. [audit_result] => 0
  154. [create_time] => 1612172838
  155. [remark] =>
  156. [delivery_name] => 顺丰同城急送
  157. )
  158. )
  159. )
  160. */
  161. public function actionGetBindAccount()
  162. {
  163. $merchant = WxOpenClass::getGhsWxInfo();
  164. $isOpen = 2;
  165. $r = miniUtil::getBindAccount($merchant, $isOpen);
  166. dd($r);
  167. }
  168. //下单 (沙箱)
  169. /**
  170. * Array
  171. * (
  172. * [resultcode] => 0
  173. * [resultmsg] => ok
  174. * [fee] => 10
  175. * [waybill_id] => test_shop_id1612365974_waybillid
  176. * [order_status] => 101
  177. * [dispatch_duration] => 300
  178. * )
  179. */
  180. public function actionCreateWaybill()
  181. {
  182. $merchant = WxOpenClass::getGhsWxInfo();
  183. $isOpen = 2;
  184. $shopId = 'test_shop_id';
  185. $shopOrderId = 'test_shop_id' . time();
  186. $appSecret = 'test_app_secrect';
  187. $data = [
  188. 'shopid' => $shopId,
  189. 'shop_order_id' => $shopOrderId,
  190. 'shop_no' => '1',
  191. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  192. 'delivery_id' => "TEST",
  193. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  194. 'sender' => [
  195. 'name' => 'test',
  196. 'city' => '厦门市',
  197. 'address' => '思明区',
  198. 'address_detail' => '软件园二期',
  199. 'phone' => '19959271111',
  200. 'lng' => 118.134343,
  201. 'lat' => 24.483566,
  202. 'coordinate_type' => 0,
  203. ],
  204. 'receiver' => [
  205. 'name' => 'test',
  206. 'city' => '厦门市',
  207. 'address' => '思明区',
  208. 'address_detail' => '软件园二期',
  209. 'phone' => '19959271111',
  210. 'lng' => 118.134343,
  211. 'lat' => 24.493566,
  212. 'coordinate_type' => 0,
  213. ],
  214. 'cargo' => [
  215. 'goods_value' => 1,
  216. 'goods_weight' => 0.1,
  217. 'cargo_first_class' => '鲜花',
  218. 'cargo_second_class' => '鲜花',
  219. ],
  220. 'order_info' => [
  221. 'order_type' => 0,
  222. ],
  223. 'shop' => [
  224. 'wxa_path' => '/shop',
  225. 'img_url' => 'http://www.baidu.com/test.png',
  226. 'goods_name' => 'test',
  227. 'goods_count' => 1,
  228. ],
  229. ];
  230. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  231. dd($r);
  232. }
  233. //获取运单数据
  234. /**
  235. * Array
  236. * (
  237. * [resultcode] => 0
  238. * [resultmsg] => ok
  239. * [order_status] => 101
  240. * [agent_info] => Array
  241. * (
  242. * )
  243. *
  244. * [waybill_id] => test_shop_id1612365974_waybillid
  245. * [rider_name] =>
  246. * [rider_phone] =>
  247. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  248. * )
  249. */
  250. public function actionGetOrder()
  251. {
  252. $shopId = 'test_shop_id';
  253. $shopOrderId = 'test_shop_id1612365974';
  254. $appSecret = 'test_app_secrect';
  255. $merchant = WxOpenClass::getGhsWxInfo();
  256. $isOpen = 2;
  257. $data = [
  258. 'shopid' => $shopId,
  259. 'shop_order_id' => $shopOrderId,
  260. 'shop_no' => '1',
  261. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  262. ];
  263. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  264. dd($r);
  265. }
  266. //沙盒 更新快递状态
  267. public function actionMockUpdateOrder()
  268. {
  269. $merchant = WxOpenClass::getGhsWxInfo();
  270. $isOpen = 2;
  271. /**
  272. * {
  273. * "shopid": "test_shop_id",
  274. * "shop_order_id": "xxxxxxxxxxx",
  275. * "waybill_id": "xxxxxxxxxxxxx",
  276. * "action_time": 12345678,
  277. * "order_status": 101,
  278. * "action_msg": "",
  279. * }
  280. */
  281. $shopId = 'test_shop_id';
  282. $shopOrderId = 'test_shop_id1612365974';
  283. $data = [
  284. 'shop_order_id' => $shopOrderId,
  285. "shopid" => $shopId,
  286. "action_time" => time(),
  287. "order_status" => 302,
  288. 'action_msg' => '状态变更',
  289. ];
  290. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  291. dd($r);
  292. }
  293. public function actionTest()
  294. {
  295. }
  296. //新增订单
  297. public function actionAddOrder()
  298. {
  299. $dada = Yii::getAlias("@vendor/dada/");
  300. require_once $dada . 'api/addOrderApi.php';
  301. require_once $dada . 'client/dadaRequestClient.php';
  302. require_once $dada . 'client/dadaResponse.php';
  303. require_once $dada . 'config/config.php';
  304. require_once $dada . 'model/orderModel.php';
  305. // isOnline 判断是否是测试环境,会有不同的域名等
  306. $isOnline = false;
  307. $sourceId = 1000000;
  308. // 初始化一个config
  309. $config = new \Config($sourceId, $isOnline);
  310. $orderModel = new \OrderModel();
  311. $orderModel->setShopNo('11047059');
  312. $orderModel->setOriginId('2018091100000002');
  313. $orderModel->setCityCode('021');
  314. $orderModel->setCargoPrice(10);
  315. $orderModel->setIsPrepay(0);
  316. $orderModel->setReceiverName('测试达达');
  317. $orderModel->setReceiverAddress('上海市崇明岛');
  318. $orderModel->setReceiverLat(31.63);
  319. $orderModel->setReceiverLng(121.41);
  320. $orderModel->setReceiverPhone('18588888888');
  321. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  322. // api主要有2个参数,一个是url, 一个是业务参数
  323. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  324. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  325. $resp = $dada_client->makeRequest();
  326. echo json_encode($resp);
  327. }
  328. //订单详情查询
  329. public function actionOrderQuery()
  330. {
  331. $dada = Yii::getAlias("@vendor/dada/");
  332. require_once $dada . 'api/OrderQueryApi.php';
  333. require_once $dada . 'client/dadaRequestClient.php';
  334. require_once $dada . 'client/dadaResponse.php';
  335. require_once $dada . 'config/config.php';
  336. require_once $dada . 'model/orderModel.php';
  337. // isOnline 判断是否是测试环境,会有不同的域名等
  338. $isOnline = false;
  339. $sourceId = 1000000;
  340. // 初始化一个config
  341. $config = new \Config($sourceId, $isOnline);
  342. $orderModel = new \OrderModel();
  343. $orderModel->setOrderId('2018091100000002');
  344. // api主要有2个参数,一个是url, 一个是业务参数
  345. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  346. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  347. $resp = $dada_client->makeRequest();
  348. echo json_encode($resp);
  349. }
  350. public function actionFocus()
  351. {
  352. $name = '花卉宝';
  353. if (getenv('YII_ENV') == 'dev') {
  354. $name = '花美灵';
  355. }
  356. $merchant = MerchantService::getByCondition(['name' => $name]);
  357. $list = wxUtil::getSubscribeUserList($merchant);
  358. dd($list);
  359. }
  360. //宝贝售出提醒 ssh 2020.1.30
  361. public function actionInform()
  362. {
  363. $merchant = MerchantService::getMerchantById(12362);
  364. $order = OrderService::getById(214810);
  365. InformAdminClass::sendComplete($order);
  366. }
  367. public function actionNotice()
  368. {
  369. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  370. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  371. echo '<pre>';
  372. print_r($data);
  373. $msg = serialize($data);
  374. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  375. }
  376. }