| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- function getOrderNo()
- {
- global $timestamp;
- return rand(11, 99) . $timestamp . rand(11, 99);
- }
- function WechatReturnSuccess()
- {
- echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
- exit();
- }
- function get_url_contents($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- function getAccessTokenByCode($code = '', $appid = '', $appsecret = '')
- {
- $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code';
- return json_decode(get_url_contents($url), true);
- }
- function getBaseAccessToken($appid = '', $appsecret = '')
- {
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
- $data = json_decode(get_url_contents($url), true);
- if (isset($data['access_token']) && isset($data['expires_in'])) {
- return $data['access_token'];
- }
- else {
- return false;
- }
- }
- ?>
|