Esempio n. 1
0
 public function update(Request $request, $uid)
 {
     $user = WechatUser::find($uid);
     if (empty($user)) {
         return $this->failure_noexists();
     }
     $keys = 'type,content';
     $data = $this->autoValidate($request, 'wechat-message.store', $keys);
     //发送消息
     $media = null;
     if ($data['type'] == 'text') {
         $media = $data['content'];
     } else {
         if ($data['type'] == 'depot') {
             $media = WechatDepot::findOrFail($data['content']);
         } else {
             $media = Attachment::findOrFail($data['content']);
         }
     }
     (new Send($user))->add($media)->send();
     return $this->success();
 }
Esempio n. 2
0
 public function getURL($url, WechatUser $user = NULL)
 {
     return url('wechat') . '?url=' . rawurlencode($url) . (!empty($user) ? '&wuid=' . rawurlencode($user->getKey()) : '');
 }
Esempio n. 3
0
 public function destroy(Request $request, $id)
 {
     empty($id) && !empty($request->input('id')) && ($id = $request->input('id'));
     $id = (array) $id;
     foreach ($id as $v) {
         $user = WechatUser::destroy($v);
     }
     return $this->success('', count($id) > 5, compact('id'));
 }
Esempio n. 4
0
 /**
  * 支付回调
  * @return [type] [description]
  */
 public function feedback(Request $request, $aid, $oid = NULL)
 {
     $aid = $request->input('aid') ?: $aid;
     $oid = $request->input('oid') ?: $oid;
     $account = WechatAccount::findOrFail($aid);
     $api = new API($account->toArray(), $account->getKey());
     $pay = new WechatPayTool($api);
     $result = $pay->notify(function ($result, &$message) use($account, $oid) {
         if ($result['return_code'] == 'SUCCESS') {
             $wechatUser = WechatUser::where('openid', $result['openid'])->firstOrFail();
             $result = array_only($result, ['return_code', 'return_msg', 'mch_id', 'device_info', 'result_code', 'err_code', 'err_code_des', 'trade_type', 'bank_type', 'total_fee', 'fee_type', 'cash_fee', 'cash_fee_type', 'coupon_fee', 'coupon_count', 'transaction_id', 'out_trade_no', 'attach', 'time_end']);
             WechatBill::create($result + ['waid' => $account->getKey(), 'wuid' => $wechatUser->getKey()]);
             if (!empty($oid)) {
                 //因为是微信访问的,只能靠记录日志来查询是否失败
                 $order = Order::findOrFail($oid);
                 $order->pay($result['total_fee']);
                 $this->dispatch((new \App\Jobs\OrderDeal($order))->delay(config('site.order.deal', 14 * 86400)));
             }
         } else {
             WechatBill::create(['return_code' => $result['return_code'], 'return_msg' => $result['return_msg'], 'waid' => $account->getKey()]);
         }
         return true;
     });
     return $result;
 }
Esempio n. 5
0
 public function bindToUser(WechatUser $wechatUser, $role_name = RoleModel::WECHATER, $cache = TRUE)
 {
     $userModel = config('auth.model');
     $user = !empty($wechatUser->uid) ? (new $userModel())->find($wechatUser->uid) : (new $userModel())->get($wechatUser->unionid);
     empty($user) && ($user = (new $userModel())->add(['username' => $wechatUser->unionid, 'password' => (new $userModel())->auto_password($wechatUser->unionid)], $role_name));
     $wechatUser->update(['uid' => $user->getKey()]);
     $hashkey = 'update-user-from-wechat-' . $user->getKey();
     if (!$cache || is_null(Cache::get($hashkey, null))) {
         $user->update(['nickname' => $wechatUser->nickname, 'gender' => $wechatUser->gender, 'avatar_aid' => $wechatUser->avatar_aid]);
         Cache::put($hashkey, time(), 1440);
         //0.5 day
     }
     return $user;
 }
Esempio n. 6
0
 /**
  * 支付回调
  * @return [type] [description]
  */
 public function feedback(Request $request, $aid, $oid = NULL)
 {
     $aid = $request->input('aid') ?: $aid;
     $oid = $request->input('oid') ?: $oid;
     $account = WechatAccount::findOrFail($aid);
     $api = new API($account->toArray(), $account->getKey());
     $pay = new WechatPayTool($api);
     $result = $pay->notify(function ($result, &$message) use($account) {
         if ($result['return_code'] == 'SUCCESS') {
             $wechatUser = WechatUser::where('openid', $result['openid'])->firstOrFail();
             $result = array_only($result, ['return_code', 'return_msg', 'mch_id', 'device_info', 'result_code', 'err_code', 'err_code_des', 'trade_type', 'bank_type', 'total_fee', 'fee_type', 'cash_fee', 'cash_fee_type', 'coupon_fee', 'coupon_count', 'transaction_id', 'out_trade_no', 'attach', 'time_end']);
             WechatBill::create($result + ['waid' => $account->getKey(), 'wuid' => $wechatUser->getKey()]);
         } else {
             WechatBill::create(['return_code' => $result['return_code'], 'return_msg' => $result['return_msg'], 'waid' => $account->getKey()]);
         }
         return true;
     });
     return $result;
 }
Esempio n. 7
0
 private function setUser(WechatUser $wechatUser)
 {
     Session::put('wechat-oauth2-' . $this->api->appid . '-user', $wechatUser->getKey());
     Session::save();
 }