Exemplo n.º 1
0
 /**
  * 发送消息.
  *
  * @param string $openId
  *
  * @return bool
  */
 public function to($openId)
 {
     if (empty($this->message)) {
         throw new Exception('未设置要发送的消息');
     }
     $this->message->to = $openId;
     return $this->http->jsonPost(self::API_MESSAGE_SEND, $this->message->buildForStaff());
 }
Exemplo n.º 2
0
 /**
  * 获取订单结果.
  *
  * @param string     $order_id 商户订单ID
  * @param bool|false $force    是否忽略缓存强制更新
  *
  * @return Bag
  *
  * @throws Exception
  * @throws \Supe\Wechat\Exception
  */
 public function getTransaction($order_id, $force = false)
 {
     $params = array();
     $params['appid'] = $this->appId;
     $params['mch_id'] = $this->mchId;
     $params['out_trade_no'] = $order_id;
     $params['nonce_str'] = md5(uniqid(microtime()));
     $signGenerator = new SignGenerator($params);
     $signGenerator->onSortAfter(function (SignGenerator $that) {
         $that->key = $this->mchKey;
     });
     $params['sign'] = $signGenerator->getResult();
     $request = XML::build($params);
     $http = new Http();
     $response = $http->request(static::QUERYORDER_URL, Http::POST, $request);
     if (empty($response)) {
         throw new Exception('Get ORDER Failure:');
     }
     $transaction = XML::parse($response);
     //返回签名数据校验
     if (empty($transaction) || empty($transaction['sign'])) {
         return false;
     }
     $sign = $transaction['sign'];
     unset($transaction['sign']);
     $signGenerator = new SignGenerator($transaction);
     $signGenerator->onSortAfter(function (SignGenerator $that) {
         $that->key = $this->mchKey;
     });
     if ($sign !== $signGenerator->getResult()) {
         return false;
     }
     // 返回结果判断
     if (isset($transaction['result_code']) && $transaction['result_code'] === 'FAIL') {
         throw new Exception($transaction['err_code'] . ': ' . $transaction['err_code_des']);
     }
     if (isset($transaction['return_code']) && $transaction['return_code'] === 'FAIL') {
         throw new Exception($transaction['return_code'] . ': ' . $transaction['return_msg']);
     }
     return $transactionInfo = new Bag($transaction);
 }
Exemplo n.º 3
0
 /**
  * 获取退款结果.
  *
  * @return array
  *
  * @throws Exception
  */
 public function getResponse()
 {
     if (is_null($this->business)) {
         throw new Exception('Business is required');
     }
     static::$params['appid'] = $this->business->appid;
     static::$params['mch_id'] = $this->business->mch_id;
     $this->checkParams();
     $signGenerator = new SignGenerator(static::$params);
     $signGenerator->onSortAfter(function (SignGenerator $that) {
         $that->key = $this->business->mch_key;
     });
     static::$params['sign'] = $signGenerator->getResult();
     $request = XML::build(static::$params);
     //设置Http使用的证书
     $options['sslcert_path'] = $this->business->getClientCert();
     $options['sslkey_path'] = $this->business->getClientKey();
     $http = new Http();
     $response = $http->request(static::REFUNDORDER_URL, Http::POST, $request, $options);
     if (empty($response)) {
         throw new Exception('Get Refund Failure:');
     }
     $refundOrder = XML::parse($response);
     if (isset($refundOrder['return_code']) && $refundOrder['return_code'] === 'FAIL') {
         throw new Exception($refundOrder['return_code'] . ': ' . $refundOrder['return_msg']);
     }
     //返回签名数据校验
     if (empty($refundOrder) || empty($refundOrder['sign'])) {
         throw new Exception('param sign is missing or empty');
     }
     $sign = $refundOrder['sign'];
     unset($refundOrder['sign']);
     $signGenerator = new SignGenerator($refundOrder);
     $signGenerator->onSortAfter(function (SignGenerator $that) {
         $that->key = $this->business->mch_key;
     });
     if ($sign !== $signGenerator->getResult()) {
         throw new Exception('check sign error');
     }
     //返回结果判断
     if (isset($refundOrder['result_code']) && $refundOrder['result_code'] === 'FAIL') {
         throw new Exception($refundOrder['err_code'] . ': ' . $refundOrder['err_code_des']);
     }
     if (isset($refundOrder['return_code']) && $refundOrder['return_code'] === 'FAIL') {
         throw new Exception($refundOrder['return_code'] . ': ' . $refundOrder['return_msg']);
     }
     return $this->refundInfo = $refundOrder;
 }
Exemplo n.º 4
0
 /**
  * 删除门店.
  *
  * @param int $storeId
  *
  * @return bool
  */
 public function delete($storeId)
 {
     $params = array('poi_id' => $storeId);
     return $this->http->jsonPost(self::API_DELETE, $params);
 }
Exemplo n.º 5
0
 /**
  * 查询红包信息.
  *
  * @param string $mchBillNumber
  *
  * @return array
  */
 public function query($mchBillNumber)
 {
     if (empty($mchBillNumber)) {
         throw new Exception('mch_id is required');
     }
     $param['mch_billno'] = $mchBillNumber;
     $param['nonce_str'] = uniqid('pre_');
     $param['mch_id'] = $this->business->mch_id;
     $param['appid'] = $this->business->appid;
     $param['bill_type'] = 'MCHT';
     $signGenerator = new SignGenerator($param);
     $me = $this;
     $signGenerator->onSortAfter(function (SignGenerator $that) use($me) {
         $that->key = $me->business->mch_key;
     });
     $sign = $signGenerator->getResult();
     $param['sign'] = $sign;
     $request = XML::build($param);
     //设置Http使用的证书
     $options['sslcert_path'] = $this->business->getClientCert();
     $options['sslkey_path'] = $this->business->getClientKey();
     $http = new Http();
     $response = $http->request(static::API_QUERY, Http::POST, $request, $options);
     if (empty($response)) {
         throw new Exception('Get LuckMoneyInfo failed.');
     }
     $result = XML::parse($response);
     return $result;
 }
Exemplo n.º 6
0
 /**
  * 获取jsticket.
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'overtrue.wechat.jsapi_ticket.' . $this->appId;
     // for php 5.3
     $appId = $this->appId;
     $appSecret = $this->appSecret;
     $cache = $this->cache;
     $apiTicket = self::API_TICKET;
     return $this->cache->get($key, function ($key) use($appId, $appSecret, $cache, $apiTicket) {
         $http = new Http(new AccessToken($appId, $appSecret));
         $result = $http->get($apiTicket);
         $cache->set($key, $result['ticket'], $result['expires_in']);
         return $result['ticket'];
     });
 }
Exemplo n.º 7
0
 /**
  * 获取永久素材列表.
  *
  * example:
  *
  * {
  *   "total_count": TOTAL_COUNT,
  *   "item_count": ITEM_COUNT,
  *   "item": [{
  *             "media_id": MEDIA_ID,
  *             "name": NAME,
  *             "update_time": UPDATE_TIME
  *         },
  *         //可能会有多个素材
  *   ]
  * }
  *
  * @param string $type
  * @param int    $offset
  * @param int    $count
  *
  * @return array
  */
 public function lists($type, $offset = 0, $count = 20)
 {
     $params = array('type' => $type, 'offset' => intval($offset), 'count' => min(20, $count));
     return $this->http->jsonPost(self::API_FOREVER_LIST, $params);
 }
Exemplo n.º 8
0
 /**
  * 语义理解.
  *
  * @param string         $keyword
  * @param array | string $categories
  * @param array          $other
  *
  * @return Bag
  */
 public function query($keyword, $categories, array $other = array())
 {
     $params = array('query' => $keyword, 'category' => implode(',', (array) $categories), 'appid' => $this->appId);
     return new Bag($this->http->jsonPost(self::API_SEARCH, array_merge($params, $other)));
 }
Exemplo n.º 9
0
 /**
  * 获取统一下单结果.
  *
  * @param bool|false $force 是否忽略缓存强制更新
  *
  * @return array
  *
  * @throws Exception
  * @throws \Supe\Wechat\Exception
  */
 public function getResponse($force = false)
 {
     if (is_null($this->business)) {
         throw new Exception('Business is required');
     }
     if (is_null($this->order)) {
         throw new Exception('Order is required');
     }
     if ($this->unifiedOrder !== null && $force === false) {
         return $this->unifiedOrder;
     }
     $params = $this->order->toArray();
     $params['appid'] = $this->business->appid;
     $params['mch_id'] = $this->business->mch_id;
     $signGenerator = new SignGenerator($params);
     $me = $this;
     $signGenerator->onSortAfter(function (SignGenerator $that) use($me) {
         $that->key = $me->business->mch_key;
     });
     $params['sign'] = $signGenerator->getResult();
     $request = XML::build($params);
     $http = new Http();
     $response = $http->request(static::UNIFIEDORDER_URL, Http::POST, $request);
     if (empty($response)) {
         throw new Exception('Get UnifiedOrder Failure:');
     }
     $unifiedOrder = XML::parse($response);
     if (isset($unifiedOrder['result_code']) && $unifiedOrder['result_code'] === 'FAIL') {
         throw new Exception($unifiedOrder['err_code'] . ': ' . $unifiedOrder['err_code_des']);
     }
     if (isset($unifiedOrder['return_code']) && $unifiedOrder['return_code'] === 'FAIL') {
         throw new Exception($unifiedOrder['return_code'] . ': ' . $unifiedOrder['return_msg']);
     }
     return $this->unifiedOrder = $unifiedOrder;
 }
Exemplo n.º 10
0
 /**
  * 按菜单ID删除菜单.
  *
  * @param int $menuId
  *
  * @return bool
  */
 public function deleteById($menuId)
 {
     $this->http->post(self::API_CONDITIONAL_DELETE, array('menuid' => $menuId));
     return true;
 }
Exemplo n.º 11
0
 /**
  * 获取用户所在的组.
  *
  * @param string $openId
  *
  * @return int
  */
 public function getGroup($openId)
 {
     $params = array('openid' => $openId);
     $response = $this->http->jsonPost(self::API_GROUP, $params);
     return $response['groupid'];
 }
Exemplo n.º 12
0
 /**
  * 创建二维码
  *
  * @param string $actionName
  * @param array  $actionInfo
  * @param bool $temporary
  * @param int $expireSeconds 过期天数,最多30天(2592000秒)
  *
  * @return Bag
  */
 protected function create($actionName, $actionInfo, $temporary = true, $expireSeconds = null)
 {
     $expireSeconds !== null || ($expireSeconds = 7 * self::DAY);
     $http = new Http(new AccessToken($this->appId, $this->appSecret));
     $params = array('action_name' => $actionName, 'action_info' => array('scene' => $actionInfo));
     if ($temporary) {
         $params['expire_seconds'] = min($expireSeconds, 30 * self::DAY);
     }
     return new Bag($http->jsonPost(self::API_CREATE, $params));
 }
Exemplo n.º 13
0
 /**
  * 查询群发消息发送状态
  *
  * @param string $msgId 全消息ID
  *
  * @return array
  */
 public function status($msgId)
 {
     return $this->http->jsonPost(self::API_GET, array('msg_id' => $msgId));
 }
Exemplo n.º 14
0
 /**
  * 获取access token.
  *
  * @param string $code
  *
  * @return string
  */
 public function getAccessPermission($code)
 {
     $params = array('appid' => $this->appId, 'secret' => $this->appSecret, 'code' => $code, 'grant_type' => 'authorization_code');
     return $this->lastPermission = $this->http->get(self::API_TOKEN_GET, $params);
 }
Exemplo n.º 15
0
 /**
  * 创建卡券货架.
  *
  * <pre>
  * $data:
  * {
  *     "banner": "http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7h  icFN",
  *     "page_title": "惠城优惠大派送",
  *     "can_share": true,
  *     "scene": 'SCENE_H5',
  *     "card_list": [
  *         {
  *             'card_id':"pXch-jnOlGtbuWwIO2NDftZeynRE",
  *             'thumb_url':"www.qq.com/a.jpg"
  *         },
  *         {
  *             'card_id':"pXch-jnAN-ZBoRbiwgqBZ1RV60fI",
  *             'thumb_url':"www.qq.com/b.jpg"
  *         }
  *     ]
  * }
  * </pre>
  *
  * @param array $data
  *
  * @return array
  */
 public function createLandingPage(array $data)
 {
     $defaultParams = array('banner' => '', 'page_title' => '', 'can_share' => true, 'scene' => 'SCENE_H5', 'card_list' => array(array('card_id' => '', 'thumb_url' => '')));
     $params = array_merge($defaultParams, $data);
     return $this->http->jsonPost(self::API_LANDINGPAGE_CREATE, $params);
 }