/** * 所有微信 jsapi调用前都需要先调用该方法 * @param array $jsApiList 见YDWX_JSAPI_XX常量 * @param $appid 作为第三方平台,配置某个授权公众号 */ function ydwx_jsapi_config(array $jsApiList, $appid = null) { $curr_page_uri = YDWX_SITE_URL . ltrim($_SERVER['REQUEST_URI'], "/"); if (YDWX_WEIXIN_COMPONENT_APP_ID) { $jsapi_ticket = YDWXHook::do_hook(YDWXHook::GET_HOST_JSAPI_TICKET, $appid); } else { $appid = YDWX_WEIXIN_APP_ID; //TODO 企业号 $jsapi_ticket = YDWXHook::do_hook(YDWXHook::GET_JSAPI_TICKET); } ob_start(); ?> <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script type="text/javascript"> <?php $time = time(); $nonceStr = uniqid(); $signStr = sha1("jsapi_ticket={$jsapi_ticket}&noncestr={$nonceStr}×tamp={$time}&url=" . $curr_page_uri); ?> wx.config({ debug: false, appId: '<?php echo $appid; ?> ', // 必填,公众号的唯一标识 timestamp:'<?php echo $time; ?> ' , // 必填,生成签名的时间戳 nonceStr: '<?php echo $nonceStr; ?> ', // 必填,生成签名的随机串 signature: '<?php echo $signStr; ?> ',// 必填,签名,见附录1 jsApiList: <?php echo json_encode($jsApiList); ?> // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.error(function(res){ alert("<?php echo "jsapi_ticket={$jsapi_ticket}&noncestr={$nonceStr}×tamp={$time}&url=" . $curr_page_uri; ?> "); alert(JSON.stringify(res)); }); </script> <?php return ob_get_clean(); }
/** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::AUTH_CANCEL, function () { //用户取消登录了做什么,如 header("Location: /signin"); die; }); YDWXHook::add_hook(YDWXHook::AUTH_FAIL, function (YDWXAuthFailResponse $info) { //用户登录是把了做什么,如 header("Location: /signin?error=" . urlencode($info->errmsg)); die; }); YDWXHook::add_hook(YDWXHook::AUTH_INAPP_SUCCESS, function (YDWXOAuthUser $userinfo) { //微信app内登录成功做什么,如判断该微信用户是否在系统中存在,不存在建立用户数据,存在标记为登录状态,并 //导航到登录后看到的页面 }); YDWXHook::add_hook(YDWXHook::AUTH_WEB_SUCCESS, function (YDWXOAuthUser $wxuser) { }); //公众号授权成功 YDWXHook::add_hook(YDWXHook::AUTH_AGENT_SUCCESS, function (array $info) { }); YDWXHook::add_hook(YDWXHook::AUTH_CROP_SUCCESS, function (YDWXOAuthCropUser $info) { //微信企业号app登录成功做什么,如判断该微信用户是否在系统中存在,不存在建立用户数据,存在标记为登录状态,并 //导航到登录后看到的页面 });
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ //门店审核通过的通知 YDWXHook::add_hook(YDWXHook::EVENT_POI_CHECK_NOTIFY, function (YDWXEventPoi_check_notify $info) { });
YDWXHook::do_hook(YDWXHook::YDWX_LOG, $data); $msg = new YDWXPaiedNotifyResponse($data); if ($msg->isSuccess()) { if ($msg->product_id) { $PayingMsg = new YDWXPayingNotifyResponse($data); $result = new YDWXPayNotifyRequest(); try { $arg = YDWXHook::do_hook(YDWXHook::QRCODE_PAY_NOTIFY_SUCCESS, $PayingMsg); $arg->openid = $PayingMsg->openid; $msg = ydwx_pay_unifiedorder($arg); $result_code = "SUCCESS"; $err_code_des = "OK"; $result->prepay_id = $msg->prepay_id; } catch (YDWXException $e) { $result_code = "FAIL"; $err_code_des = $e->getMessage(); } $result->result_code = $result_code; $result->err_code_des = $err_code_des; $result->sign(); echo $result->toXMLString(); } else { if (YDWXHook::do_hook(YDWXHook::PAY_NOTIFY_SUCCESS, $msg)) { ob_clean(); echo "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"; } } die; } else { YDWXHook::do_hook(YDWXHook::PAY_NOTIFY_ERROR, $msg); }
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::EVENT_MSG_TEXT, function (YDWXEventMsgText $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_LOCATION, function (YDWXEventLocation $msg) { });
<?php /** * 微信支付统一下单接口,生成预支付id,由ydwx的jsPayApi负责调起,与其配合完成微信内H5js调起支付 */ chdir(dirname(__FILE__)); //把工作目录切换到文件所在目录 include_once dirname(__FILE__) . '/__config__.php'; $appid = $_POST['appid']; $arg = new YDWXPayUnifiedOrderRequest(); $arg->openid = $_POST['openid']; $arg->out_trade_no = $_POST['trace_no']; $arg->total_fee = intval($_POST['price'] * 100); $arg->attach = $_POST['attach']; $arg->body = $_POST['pay_desc']; try { $mchkey = YDWX_WEIXIN_COMPONENT_APP_ID ? YDWXHook::do_hook(YDWXHook::GET_HOST_MCH_KEY, $appid) : YDWX_WEIXIN_MCH_KEY; $msg = ydwx_pay_unifiedorder($arg); $str = "appId=" . $appid . "&nonceStr=" . $_POST['noncestr'] . "&package=prepay_id=" . $msg->prepay_id . "&signType=MD5&timeStamp=" . $_POST['timestamp']; $sign = strtoupper(md5($str . "&key=" . $mchkey)); echo json_encode(ydwx_success(array("prepay_id" => $msg->prepay_id, "paySign" => $sign, "trade_no" => $_POST['trace_no']))); die; } catch (YDWXException $e) { echo json_encode(ydwx_error($e->getMessage())); die; }
<?php /** * 网站进行微信OAuth登陆 * 该页面可通过Redirect方式进行访问,或者直接在需要的地方include_once */ chdir(dirname(__FILE__)); //把工作目录切换到文件所在目录 include_once dirname(__FILE__) . '/__config__.php'; // state为交互时双方都会带着的get参数,用于做一些逻辑判断,如果没指定,则默认一个 if (!$state) { $state = "fromydwx"; } $redirect = YDWX_SITE_URL . 'ydwx/webauth.php'; if (!@$_GET['code'] && !@$_GET['state']) { ob_clean(); header("Location: https://open.weixin.qq.com/connect/qrconnect?appid=" . YDWX_WEIXIN_WEB_APP_ID . "&redirect_uri={$redirect}&response_type=code&scope=snsapi_login&state={$state}#wechat_redirect"); die; } if (!@$_GET['code'] && @$_GET['state']) { YDWXHook::do_hook(YDWXHook::AUTH_CANCEL); die; } $http = new YDHttp(); $info = json_decode($http->get("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . YDWX_WEIXIN_WEB_APP_ID . "&secret=" . YDWX_WEIXIN_WEB_APP_SECRET . "&code=" . $_GET['code'] . "&grant_type=authorization_code"), true); if (!@$info['openid']) { YDWXHook::do_hook(YDWXHook::AUTH_FAIL, YDWXAuthFailResponse::errMsg($info['errmsg'], $info['errcode'])); die; } YDWXHook::do_hook(YDWXHook::AUTH_WEB_SUCCESS, ydwx_sns_userinfo($info['access_token'], $info['openid'], $_GET['state']));
/** * Make an HTTP request * * @return API results */ protected function http($url, $method, $postfields = NULL, $multi = false) { curl_setopt($this->ci, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($this->ci, CURLOPT_SSL_VERIFYHOST, 1); if (YDWX_WEIXIN_COMPONENT_APP_ID) { $cert_file = YDWXHook::do_hook(YDWXHook::GET_HOST_APICLIENT_CERT_PATH, $this->appid); if (SAE_TMP_PATH) { if (copy($cert_file, SAE_TMP_PATH . "cert.pem")) { $cert_file = SAE_TMP_PATH . "cert.pem"; } } } else { $cert_file = YDWX_WEIXIN_APICLIENT_CERT; } curl_setopt($this->ci, CURLOPT_SSLCERTTYPE, 'PEM'); curl_setopt($this->ci, CURLOPT_SSLCERT, $cert_file); if (YDWX_WEIXIN_COMPONENT_APP_ID) { $key_file = YDWXHook::do_hook(YDWXHook::GET_HOST_APICLIENT_KEY_PATH, $this->appid); if (SAE_TMP_PATH) { if (copy($key_file, SAE_TMP_PATH . "key.pem")) { $key_file = SAE_TMP_PATH . "key.pem"; } } } else { $key_file = YDWX_WEIXIN_APICLIENT_KEY; } curl_setopt($this->ci, CURLOPT_SSLKEYTYPE, 'PEM'); curl_setopt($this->ci, CURLOPT_SSLKEY, $key_file); curl_setopt($this->ci, CURLOPT_SSLKEYPASSWD, YDWX_WEIXIN_COMPONENT_APP_ID ? YDWXHook::do_hook(YDWXHook::GET_HOST_MCH_KEY, $this->appid) : YDWX_WEIXIN_MCH_KEY); return parent::http($url, $method, $postfields, $multi); }
YDWXHook::do_hook(YDWXHook::AUTH_FAIL, YDWXAuthFailResponse::errMsg($info['errmsg'], $info['errcode'])); die; } if ($isAgent) { $access_token = YDWXHook::do_hook(YDWXHook::GET_HOST_ACCESS_TOKEN, $appid); } else { $access_token = YDWXHook::do_hook(YDWXHook::GET_ACCESS_TOKEN); } if ($access_token) { try { $user = ydwx_user_info($access_token, $info['openid']); } catch (\Exception $e) { $user = new YDWXSubscribeUser(); $user->openid = $info['openid']; } } else { $user = new YDWXSubscribeUser(); $user->openid = $info['openid']; } $user->appid = $appid; $user->state = $_GET['state']; YDWXHook::do_hook(YDWXHook::AUTH_INAPP_SUCCESS, $user); die; } //企业号返回的是code,可直接获取用户的信息TODO 是否企业号也会托管,那这里是不是该拿托管的企业号token $access_token = YDWXHook::do_hook(YDWXHook::GET_ACCESS_TOKEN); if ($access_token) { YDWXHook::do_hook(YDWXHook::AUTH_CROP_SUCCESS, ydwx_crop_user_info($access_token, $_GET['code'], $_GET['state'])); } else { YDWXHook::do_hook(YDWXHook::AUTH_FAIL, YDWXAuthFailResponse::errMsg("未取得access token")); }
<?php /** * $oldcwd = getcwd(); * #hook * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::EVENT_CARD_NOT_PASS_CHECK, function (YDWXEventCard_not_pass_check $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_CARD_PASS_CHECK, function (YDWXEventCard_pass_check $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_USER_CONSUME_CARD, function (YDWXEventUserConsumeCard $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_USER_DEL_CARD, function (YDWXEventUser_del_card $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_USER_ENTER_SESSION_FROM_CARD, function (YDWXEventUser_enter_session_from_card $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_USER_GET_CARD, function (YDWXEventUser_get_card $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_USER_PAID_BY_CARD, function (YDWXEventUserPaidByCard $msg) { }); YDWXHook::add_hook(YDWXHook::EVENT_USER_VIEW_CARD, function ($msg) { });
$tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if ($tmpStr == $signature) { echo $echostr; } } die; } //微信通知处理 $from_xml = @$GLOBALS["HTTP_RAW_POST_DATA"]; $msg_sign = $_GET["msg_signature"]; $timeStamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; if (YDWX_WEIXIN_COMPONENT_APP_ID) { $crypt = new WXBizMsgCrypt(YDWX_WEIXIN_COMPONENT_TOKEN, YDWX_WEIXIN_COMPONENT_ENCODING_AES_KEY, YDWX_WEIXIN_COMPONENT_APP_ID); } else { $crypt = new WXBizMsgCrypt(YDWX_WEIXIN_TOKEN, YDWX_WEIXIN_ENCODING_AES_KEY, YDWX_WEIXIN_APP_ID); } $msg = ''; $errCode = $crypt->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg); if (!$msg) { die("success"); } YDWXHook::do_hook(YDWXHook::YDWX_LOG, $msg . $APPID); //微信事件指派 $wxevent = YDWXEvent::CreateEventMsg($msg); if (@$APPID) { $wxevent->APPID = $APPID; } YDWXHook::do_hook($wxevent->HookName(), $wxevent);
} catch (\Exception $e) { echo " agent_access_token: " . $e->getMessage(); } } else { //刷新access_token try { if (YDWX_WEIXIN_ACCOUNT_TYPE == YDWX_WEIXIN_ACCOUNT_TYPE_CROP) { //企业号 $accessToken = ydwx_qy_refresh_access_token(YDWX_WEIXIN_CROP_ID, YDWX_WEIXIN_CROP_SECRET); } else { //其它微信号 $accessToken = ydwx_refresh_access_token(YDWX_WEIXIN_APP_ID, YDWX_WEIXIN_APP_SECRET); } YDWXHook::do_hook(YDWXHook::REFRESH_ACCESS_TOKEN, $accessToken); //刷新jsapi ticket if (YDWX_WEIXIN_ACCOUNT_TYPE == YDWX_WEIXIN_ACCOUNT_TYPE_CROP) { //企业号 $ticket = ydwx_qy_refresh_jsapi_ticket($accessToken->access_token); } else { //其它微信号 $ticket = ydwx_refresh_jsapi_ticket($accessToken->access_token); } YDWXHook::do_hook(YDWXHook::REFRESH_JSAPI_TICKET, $ticket); //刷新微信card api ticket $ticket = ydwx_refresh_card_jsapi_ticket($accessToken->access_token); YDWXHook::do_hook(YDWXHook::REFRESH_CARD_JSAPI_TICKET, $ticket); } catch (\Exception $e) { echo " accessToken: " . $e->errmsg . "<br/>"; } } die("success");
/** * 该 API 用于第三方平台确认接受公众号将某权限集高级权限的授权 * @param unknown $appid * @param unknown $funcscope_category_id 功能集合,见YDWX_FUNC_XX常量 * @param boolean $confirm true 确认 false取消 * @throws YDWXException * @return boolean */ function ydwx_agent_confirm_authorization($appid, $funcscope_category_id, $confirm) { $accessToken = YDWXHook::do_hook(YDWXHook::GET_AGENT_ACCESS_TOKEN); $http = new YDHttp(); $info = $http->post(YDWX_WEIXIN_BASE_URL . "component/api_confirm_authorization?component_access_token={$accessToken}", ydwx_json_encode(array("component_appid" => YDWX_WEIXIN_COMPONENT_APP_ID, "authorizer_appid" => $appid, "funcscope_category_id" => $funcscope_category_id, "confirm_value" => $confirm ? 1 : 2))); $msg = new YDWXResponse($info); if ($msg->isSuccess()) { return true; } throw new YDWXException($msg->errmsg); }
<?php /** * $oldcwd = getcwd(); * #hook * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::EVENT_COMPONENT_VERIFY_TICKET, function (YDWXEventComponent_verify_ticket $info) { }); YDWXHook::add_hook(YDWXHook::GET_VERIFY_TICKET, function () { }); YDWXHook::add_hook(YDWXHook::REFRESH_AGENT_ACCESS_TOKEN, function (YDWXAccessTokenResponse $info) { }); YDWXHook::add_hook(YDWXHook::GET_AGENT_ACCESS_TOKEN, function () { });
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::EVENT_SHAKEAROUNDUSERSHAKE, function (YDWXEventShakearoundusershake $msg) { });
* @var unknown */ define("YDWX_WEIXIN_APICLIENT_CERT", ""); /** * 证书密钥pem格式(apiclient_key.pem),建议放在非web访问路径中 */ define("YDWX_WEIXIN_APICLIENT_KEY", ""); /** * CA证书(rootca.pem),建议放在非web访问路径中 */ define("YDWX_WEIXIN_ROOTCA", ""); //企业号的cropid define("YDWX_WEIXIN_CROP_ID", ""); define("YDWX_WEIXIN_CROP_SECRET", ""); //企业应用的id define("YDWX_WEIXIN_CROP_AGENT_ID", ""); define("YDWX_WEIXIN_ACCOUNT_TYPE", YDWX_WEIXIN_ACCOUNT_TYPE_SERVICE); //公众号类型 //公众号是否认证 define("YDWX_WEIXIN_IS_AUTHED", true); # # # 填写结束 # # YDWXHook::include_files($cwd . "/models"); YDWXHook::include_files($cwd . "/functions"); //包含功能函数库 #加载你自己的hook目录 YDWXHook::include_files(YDWX_HOOK_DIR);
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::YDWX_LOG, function ($msg) { });
* #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ // access token 刷新 YDWXHook::add_hook(YDWXHook::REFRESH_ACCESS_TOKEN, function (YDWXAccessTokenResponse $info) { }); YDWXHook::add_hook(YDWXHook::REFRESH_JSAPI_TICKET, function (YDWXJsapiTicketResponse $info) { }); YDWXHook::add_hook(YDWXHook::REFRESH_CARD_JSAPI_TICKET, function (YDWXJsapiTicketResponse $info) { }); // access token 刷新 YDWXHook::add_hook(YDWXHook::GET_ACCESS_TOKEN, function ($info) { }); YDWXHook::add_hook(YDWXHook::GET_JSAPI_TICKET, function ($info) { }); YDWXHook::add_hook(YDWXHook::GET_CARD_JSAPI_TICKET, function ($info) { }); //获取托管的公众号的jsapi ticket YDWXHook::add_hook(YDWXHook::GET_HOST_JSAPI_TICKET, function ($appid) { }); //获取托管的公众号的card jsapi ticket YDWXHook::add_hook(YDWXHook::GET_HOST_CARD_JSAPI_TICKET, function ($appid) { }); YDWXHook::add_hook(YDWXHook::EVENT_SUBSCRIBE, function (YDWXEventSubscribe $info) { // 用户订阅后的回调 }); YDWXHook::add_hook(YDWXHook::EVENT_UNSUBSCRIBE, function ($info) { // 用户取消订阅后的回调 });
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::GET_HOST_MCH_KEY, function ($appid) { }); YDWXHook::add_hook(YDWXHook::GET_HOST_MCH_ID, function ($appid) { }); YDWXHook::add_hook(YDWXHook::GET_HOST_APICLIENT_CERT_PATH, function ($appid) { }); YDWXHook::add_hook(YDWXHook::GET_HOST_APICLIENT_KEY_PATH, function ($appid) { }); YDWXHook::add_hook(YDWXHook::GET_HOST_ROOT_CA, function ($appid) { }); YDWXHook::add_hook(YDWXHook::PAY_NOTIFY_ERROR, function ($error) { }); YDWXHook::add_hook(YDWXHook::PAY_NOTIFY_SUCCESS, function (YDWXPaiedNotifyResponse $msg) { // 支付成功的处理 return true; });
$card_jsapi_ticket = YDWXHook::do_hook(YDWXHook::GET_HOST_CARD_JSAPI_TICKET, $appid); } else { $card_jsapi_ticket = YDWXHook::do_hook(YDWXHook::GET_CARD_JSAPI_TICKET); } $array = array($nonceStr, $card_jsapi_ticket, $time, $shopId, $cardType, $cardId); $array = YDWXRequest::ignoreNull($array); sort($array); $cardSignStr = sha1(join("", $array)); echo json_encode(ydwx_success(array("shopId" => $shopId, "cardType" => $cardType, "cardId" => $cardId, "nonceStr" => $nonceStr, "time" => $time, "cardSign" => $cardSignStr))); die; } if ($action == "addCard") { $exts = $_POST['exts']; $appid = $_POST['appid']; if (YDWX_WEIXIN_COMPONENT_APP_ID) { $card_jsapi_ticket = YDWXHook::do_hook(YDWXHook::GET_HOST_CARD_JSAPI_TICKET, $appid); } else { $card_jsapi_ticket = YDWXHook::do_hook(YDWXHook::GET_CARD_JSAPI_TICKET); } $array = array(); foreach ($exts as $ext) { $extObj = new YDWXCardExt(); $extObj->cardId = $ext['cardId']; $extObj->code = @$ext['code']; $extObj->openid = @$ext['openid']; $extObj->jsApiTicket = $card_jsapi_ticket; $array[] = $extObj->toArray(); } echo json_encode(ydwx_success($array)); die; }
<?php /** * 公众号授权第三方平台托管流程 */ chdir(dirname(__FILE__)); include_once dirname(__FILE__) . '/__config__.php'; $auth_code = @$_GET["auth_code"]; if (!$auth_code) { YDWXHook::do_hook(YDWXHook::AUTH_CANCEL); die; } try { $auth_info = ydwx_agent_query_auth($auth_code); } catch (\Exception $e) { YDWXHook::do_hook(YDWXHook::AUTH_FAIL, YDWXAuthFailResponse::errMsg($e->getMessage())); die; } YDWXHook::do_hook(YDWXHook::AUTH_AGENT_SUCCESS, array($auth_info, ydwx_agent_get_auth_account($auth_info->authorizer_appid)));
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::EVENT_CLICK, function (YDWXEventClick $event) { });
<?php /** * $oldcwd = getcwd(); * #如需要把工作目录切换到你项目中去,并包含项目的库文件来实现hook中的逻辑 * chdir($your_work_dir); * include_once 'your-lib-file.php'; * chdir ( $oldcwd ); */ YDWXHook::add_hook(YDWXHook::EVENT_SHAKEAROUNDLOTTERYBIND, function (YDWXEventShakearoundLotteryBind $bind) { //微信红包绑定事件 });
/** * 扫码支付二维码内容(模式一) * 把返回的内容生成二维码后,用户扫码后回回调pay-notify.php * * * 建议采用http://ydimage.yidianhulian.com/qrcode?str=二维码内容来生产二维码 * * 可以把返回结果再次调用ydwx_pay_short_qrcode()得到更精简的二维码内容,减少二维码复杂度 * * @param unknown $product_id 你系统的产品id * @param unknown $appid 当前公众号appid,如果不是第三方平台,则传入YDWX_WEIXIN_APP_ID */ function ydwx_pay_product_qrcode($product_id, $appid) { $nonceStr = uniqid(); $time_stamp = time(); $mchkey = YDWX_WEIXIN_COMPONENT_APP_ID ? YDWXHook::do_hook(YDWXHook::GET_HOST_MCH_KEY, $appid) : YDWX_WEIXIN_MCH_KEY; $mchid = YDWX_WEIXIN_COMPONENT_APP_ID ? YDWXHook::do_hook(YDWXHook::GET_HOST_MCH_ID, $appid) : YDWX_WEIXIN_MCH_ID; $str = "appid=" . $appid . "&mch_id=" . $mchid . "&nonce_str=" . $nonceStr . "&product_id=" . $product_id . "&time_stamp=" . $time_stamp; $signStr = strtoupper(md5($str . "&key=" . $mchkey)); return "weixin://wxpay/bizpayurl?sign={$signStr}&appid=" . $appid . "&mch_id=" . $mchid . "&product_id={$product_id}&time_stamp={$time_stamp}&nonce_str={$nonceStr}"; }