| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- <?php
- namespace ghs\controllers;
- use biz\sj\services\MerchantService;
- use bizGhs\express\services\DadaExpressServices;
- use bizGhs\order\classes\OrderClass;
- use bizHd\message\classes\InformAdminClass;
- use bizHd\message\services\InformAdminService;
- use bizHd\order\services\OrderService;
- use bizHd\wx\classes\WxOpenClass;
- use bizGhs\express\services\MiniExpressService;
- use bizGhs\product\classes\ProductClass;
- use common\components\baiduAip;
- use common\components\barcodeUtil;
- use common\components\lakala\Lakala;
- use common\components\miniUtil;
- use common\components\orderSn;
- use common\components\oss;
- use common\components\wxUtil;
- use Yii;
- use common\components\util;
- class TestController extends BaseController
- {
- public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
- public function actionAliRun()
- {
- // $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/cs_private_key.pem';
- // $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/cs_cert.cer';
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/api_cert.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => '8224050539900TF',
- 'term_no' => 'C7632663',
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $outTradeNo = orderSn::getPurchaseSn();
- $price = 0.1;
- $response = $laResource->driveAliPay($outTradeNo, $price);
- print_r($response);die;
- if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
- echo '<pre>';
- echo "下单成功<br/>";
- print_r($response);
- } else {
- echo '<pre>';
- echo "下单失败<br/>";
- print_r($response);
- }
- }
- public function actionRun()
- {
- // $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/cs_private_key.pem';
- // $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/cs_cert.cer';
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/api_cert.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => '8224050539900TF',
- 'term_no' => 'C7632663',
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $outTradeNo = orderSn::getPurchaseSn();
- $price = 0.1;
- $response = $laResource->driveWxPay($outTradeNo, $price);
- if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
- echo '<pre>';
- echo "下单成功<br/>";
- print_r($response);
- } else {
- echo '<pre>';
- echo "下单失败<br/>";
- print_r($response);
- }
- }
- public function actionIndex()
- {
- //header('Content-type:image/png');
- $productId = 1;
- $barcode = barcodeUtil::barcodeGeneratorPNG($productId);
- oss::uploadContent("ghs/barcode/" . $productId . '.png', $barcode);
- $barcode = base64_encode($barcode);
- echo ' <img src="data:image/png;base64,' . $barcode . '"/>';
- // $merchantExtend = WxOpenClass::getGhsWxInfo();
- // // $res = baiduAip::transfer("你好");
- // dd($merchantExtend);
- }
- //dada 城市code
- public function actionDadaCityCode()
- {
- $res = dada::getCityCode(0);
- util::success($res);
- }
- //理由
- public function actionDadaReasons()
- {
- $res = dada::getCancelReason(0);
- util::success($res);
- }
- //达达 :下单
- public function actionDadaAddOrder()
- {
- $orderSn = 'XSD_CS26316851';
- $orderInfo = OrderClass::getByOrderSn($orderSn);
- $res = DadaExpressServices::addOrder($orderInfo);
- util::success($res);
- }
- //重发快递
- public function actionDadaReAdd()
- {
- $orderSn = 'XSD_CS26316851';
- $orderInfo = OrderClass::getByOrderSn($orderSn);
- $res = DadaExpressServices::reAddOrder($orderInfo);
- util::success($res);
- }
- //达达状态查询
- public function actionDadaOrderStatus()
- {
- $orderSn = 'XSD_CS26316851';
- $res = DadaExpressServices::statusOrder($orderSn);
- util::success($res);
- }
- //达达取消下单
- public function actionDadaCancelOrder()
- {
- $orderSn = 'XSD_CS26316851';
- $res = DadaExpressServices::cancelOrder($orderSn, 1);
- util::success($res);
- }
- //获取已支持的配送公司列表接口
- public function actionGetAllDelivery()
- {
- $data = MiniExpressService::getAllImmeDelivery();
- util::success($data);
- }
- //即时配送
- /*
- * Array
- (
- [resultcode] => 0
- [resultmsg] => OK
- [shop_list] => Array
- (
- [0] => Array
- (
- [shopid] => 1588714266
- [delivery_id] => SFTC
- [audit_result] => 0
- [create_time] => 1612172838
- [remark] =>
- [delivery_name] => 顺丰同城急送
- )
- )
- )
- */
- public function actionGetBindAccount()
- {
- $merchant = WxOpenClass::getGhsWxInfo();
- $isOpen = 2;
- $r = miniUtil::getBindAccount($merchant, $isOpen);
- dd($r);
- }
- //下单 (沙箱)
- /**
- * Array
- * (
- * [resultcode] => 0
- * [resultmsg] => ok
- * [fee] => 10
- * [waybill_id] => test_shop_id1612365974_waybillid
- * [order_status] => 101
- * [dispatch_duration] => 300
- * )
- */
- public function actionCreateWaybill()
- {
- $merchant = WxOpenClass::getGhsWxInfo();
- $isOpen = 2;
- $shopId = 'test_shop_id';
- $shopOrderId = 'test_shop_id' . time();
- $appSecret = 'test_app_secrect';
- $data = [
- 'shopid' => $shopId,
- 'shop_order_id' => $shopOrderId,
- 'shop_no' => '1',
- 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
- 'delivery_id' => "TEST",
- 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
- 'sender' => [
- 'name' => 'test',
- 'city' => '厦门市',
- 'address' => '思明区',
- 'address_detail' => '软件园二期',
- 'phone' => '19959271111',
- 'lng' => 118.134343,
- 'lat' => 24.483566,
- 'coordinate_type' => 0,
- ],
- 'receiver' => [
- 'name' => 'test',
- 'city' => '厦门市',
- 'address' => '思明区',
- 'address_detail' => '软件园二期',
- 'phone' => '19959271111',
- 'lng' => 118.134343,
- 'lat' => 24.493566,
- 'coordinate_type' => 0,
- ],
- 'cargo' => [
- 'goods_value' => 1,
- 'goods_weight' => 0.1,
- 'cargo_first_class' => '鲜花',
- 'cargo_second_class' => '鲜花',
- ],
- 'order_info' => [
- 'order_type' => 0,
- ],
- 'shop' => [
- 'wxa_path' => '/shop',
- 'img_url' => 'http://www.baidu.com/test.png',
- 'goods_name' => 'test',
- 'goods_count' => 1,
- ],
- ];
- $r = miniUtil::addOrder($data, $merchant, $isOpen);
- dd($r);
- }
- //获取运单数据
- /**
- * Array
- * (
- * [resultcode] => 0
- * [resultmsg] => ok
- * [order_status] => 101
- * [agent_info] => Array
- * (
- * )
- *
- * [waybill_id] => test_shop_id1612365974_waybillid
- * [rider_name] =>
- * [rider_phone] =>
- * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
- * )
- */
- public function actionGetOrder()
- {
- $shopId = 'test_shop_id';
- $shopOrderId = 'test_shop_id1612365974';
- $appSecret = 'test_app_secrect';
- $merchant = WxOpenClass::getGhsWxInfo();
- $isOpen = 2;
- $data = [
- 'shopid' => $shopId,
- 'shop_order_id' => $shopOrderId,
- 'shop_no' => '1',
- 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
- ];
- $r = miniUtil::getOrder($data, $merchant, $isOpen);
- dd($r);
- }
- //沙盒 更新快递状态
- public function actionMockUpdateOrder()
- {
- $merchant = WxOpenClass::getGhsWxInfo();
- $isOpen = 2;
- /**
- * {
- * "shopid": "test_shop_id",
- * "shop_order_id": "xxxxxxxxxxx",
- * "waybill_id": "xxxxxxxxxxxxx",
- * "action_time": 12345678,
- * "order_status": 101,
- * "action_msg": "",
- * }
- */
- $shopId = 'test_shop_id';
- $shopOrderId = 'test_shop_id1612365974';
- $data = [
- 'shop_order_id' => $shopOrderId,
- "shopid" => $shopId,
- "action_time" => time(),
- "order_status" => 302,
- 'action_msg' => '状态变更',
- ];
- $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
- dd($r);
- }
- public function actionTest()
- {
- }
- //新增订单
- public function actionAddOrder()
- {
- $dada = Yii::getAlias("@vendor/dada/");
- require_once $dada . 'api/addOrderApi.php';
- require_once $dada . 'client/dadaRequestClient.php';
- require_once $dada . 'client/dadaResponse.php';
- require_once $dada . 'config/config.php';
- require_once $dada . 'model/orderModel.php';
- // isOnline 判断是否是测试环境,会有不同的域名等
- $isOnline = false;
- $sourceId = 1000000;
- // 初始化一个config
- $config = new \Config($sourceId, $isOnline);
- $orderModel = new \OrderModel();
- $orderModel->setShopNo('11047059');
- $orderModel->setOriginId('2018091100000002');
- $orderModel->setCityCode('021');
- $orderModel->setCargoPrice(10);
- $orderModel->setIsPrepay(0);
- $orderModel->setReceiverName('测试达达');
- $orderModel->setReceiverAddress('上海市崇明岛');
- $orderModel->setReceiverLat(31.63);
- $orderModel->setReceiverLng(121.41);
- $orderModel->setReceiverPhone('18588888888');
- $orderModel->setCallback('http://api.b.huaml.com/data/request');
- // api主要有2个参数,一个是url, 一个是业务参数
- $addOrderApi = new \AddOrderApi(json_encode($orderModel));
- $dada_client = new \DadaRequestClient($config, $addOrderApi);
- $resp = $dada_client->makeRequest();
- echo json_encode($resp);
- }
- //订单详情查询
- public function actionOrderQuery()
- {
- $dada = Yii::getAlias("@vendor/dada/");
- require_once $dada . 'api/OrderQueryApi.php';
- require_once $dada . 'client/dadaRequestClient.php';
- require_once $dada . 'client/dadaResponse.php';
- require_once $dada . 'config/config.php';
- require_once $dada . 'model/orderModel.php';
- // isOnline 判断是否是测试环境,会有不同的域名等
- $isOnline = false;
- $sourceId = 1000000;
- // 初始化一个config
- $config = new \Config($sourceId, $isOnline);
- $orderModel = new \OrderModel();
- $orderModel->setOrderId('2018091100000002');
- // api主要有2个参数,一个是url, 一个是业务参数
- $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
- $dada_client = new \DadaRequestClient($config, $addOrderApi);
- $resp = $dada_client->makeRequest();
- echo json_encode($resp);
- }
- public function actionFocus()
- {
- $name = '花卉宝';
- if (getenv('YII_ENV') == 'dev') {
- $name = '花美灵';
- }
- $merchant = MerchantService::getByCondition(['name' => $name]);
- $list = wxUtil::getSubscribeUserList($merchant);
- dd($list);
- }
- //宝贝售出提醒 ssh 2020.1.30
- public function actionInform()
- {
- $merchant = MerchantService::getMerchantById(12362);
- $order = OrderService::getById(214810);
- InformAdminClass::sendComplete($order);
- }
- public function actionNotice()
- {
- $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
- $producer = Yii::$app->rabbitmq->getProducer('informProducer');
- echo '<pre>';
- print_r($data);
- $msg = serialize($data);
- $r = $producer->publish($msg, 'informExchange', 'informRoute');
- }
- }
|