Showing
53 changed files
with
4719 additions
and
0 deletions
Too many changes to show.
To preserve performance only 53 of 1339 files are displayed.
.coveralls.yml
0 → 100644
.env.example
0 → 100644
1 | +APP_ENV=local | ||
2 | +APP_KEY=base64:8i/NA9BZqqS8Rd/tL3ctIGKsh37OkOrY3iRXoxLr1HQ= | ||
3 | +APP_DEBUG=true | ||
4 | +APP_LOG_LEVEL=debug | ||
5 | +APP_URL=http://153.34.241.104:8888/ | ||
6 | +APP_LOCALE=zh | ||
7 | +APP_FALLBACK_LOCALE=en | ||
8 | +APP_LOCALE_PHP=zh_CN | ||
9 | +APP_TIMEZONE=PRC | ||
10 | + | ||
11 | +USER_IMAGE_URL_PREFIX=http://oigy7evem.bkt.clouddn.com/ | ||
12 | + | ||
13 | +SMS_BASE_URL=https://api.netease.im/sms/ | ||
14 | +SMS_TEMPLATE_URL=sendtemplate.action | ||
15 | +SMS_CODE_URL=sendcode.action | ||
16 | +SMS_VERIFY_URL=verifycode.action | ||
17 | +SMS_APP_KEY=ebf758ec81cf9a4cbb7b59eefef0a9ee | ||
18 | +SMS_APP_SECRET=e4cc7ab12c8f | ||
19 | +SMS_CODE_LEN=4 | ||
20 | + | ||
21 | +APP_STORE_HACK_ON=1 | ||
22 | +APP_STORE_HACK_TELEPHONE=15501681055 | ||
23 | +APP_STORE_HACK_SMS=1989 | ||
24 | + | ||
25 | +HE_CLOUD_API_ADDRESS=http://api.js.cmcconenet.com | ||
26 | +HE_CLOUD_API_KEY=aFpHq1TkvggQrHkTgMlTKA2pXAI= | ||
27 | +HE_CLOUD_TOKEN=Rqb8bogu6hchuIMaNzfzFpsDDOSuxKJB | ||
28 | +HE_CLOUD_ENCODING_AES_KEY=LhNFQMGp6K86jCxF5QyJCf5GOe7zbhyJztRkx2nHDTr | ||
29 | + | ||
30 | +QINIU_ACCESS_KEY=wlMcrYajGXGtzOfzJKtVRhx_nyk_NDLhWs43sACg | ||
31 | +QINIU_SECRET=UUpPA9ek1VAuFEqHhNa-kw6bTL83D1UKYPBU2tqz | ||
32 | +QINIU_CALLBACK_BASE_URL=https://apidev.tg.shzaonuo.com/ | ||
33 | +QINIU_USER_BUCKET=user | ||
34 | +QINIU_USER_BUCKET_URL=http://p2a3zwe04.bkt.clouddn.com/ | ||
35 | +QINIU_SHOP_BUCKET=shop | ||
36 | +QINIU_SHOP_BUCKET_URL=http://p2a3w4wx1.bkt.clouddn.com/ | ||
37 | +QINIU_REPAIR_BUCKET=repair | ||
38 | +QINIU_REPAIR_BUCKET_URL=http://p2a3dr73w.bkt.clouddn.com/ | ||
39 | + | ||
40 | +WEBSOCKET_PUSH_SERVER=172.17.16.16:1238 | ||
41 | + | ||
42 | +AMAP_API_URL=http://restapi.amap.com/v3/geocode/regeo | ||
43 | +AMAP_KEY=de5fb056635efe79e01afbe47d1563de | ||
44 | + | ||
45 | +WECHAT_APPID=wx4891d9f7b1305812 | ||
46 | +WECHAT_APPSECRET=0bfa4f989ffe981623074a30784b9c3c | ||
47 | + | ||
48 | +WECHAT_MINI_PROGRAM_ID=wx3c08b58c17c85a13 | ||
49 | +WECHAT_MINI_PROGRAM_SECRET=21025e813ef22e4cfef6d583bcb766e2 | ||
50 | + | ||
51 | +WECHAT_MCHID=1446773302 | ||
52 | +WECHAT_KEY=xiaobanjMHSkIp96j8MB8xKxbWebl9jE | ||
53 | +WECHAT_UNIFIED_ORDER_URL=https://api.mch.weixin.qq.com/pay/unifiedorder | ||
54 | +WECHAT_OPEN_ID_URL=https://api.weixin.qq.com/sns/jscode2session | ||
55 | +WECHAT_REFUND_URL=https://api.mch.weixin.qq.com/secapi/pay/refund | ||
56 | +WECHAT_QUERY_URL=https://api.mch.weixin.qq.com/pay/orderquery | ||
57 | +WECHAT_SSL_CERT_PATH=app/Certs/Wechat/apiclient_cert.pem | ||
58 | +WECHAT_SSL_KEY_PATH=app/Certs/Wechat/apiclient_key.pem | ||
59 | + | ||
60 | +QQ_ANDROID_APP_ID=1106267569 | ||
61 | +QQ_ANDROID_APP_SECRET=G7FtJy6p0pSaB9ro | ||
62 | +QQ_iOS_APP_ID=1106267645 | ||
63 | +QQ_ANDROID_APP_SECRET=Qb4PARHVWPgAmh5m | ||
64 | + | ||
65 | +ALIPAY_APPID=2017070107614869 | ||
66 | +ALIPAY_MINIPROGRAM_APPID=2017090908631937 | ||
67 | +ALIPAY_PUB_KEY=app/Certs/Alipay/alipay_public_key.pem | ||
68 | +ALIPAY_MCH_PUB_KEY=app/Certs/Alipay/alipay_mch_public_key.pem | ||
69 | +ALIPAY_MCH_PRIVATE_KEY=app/Certs/Alipay/alipay_mch_private_key.pem | ||
70 | +ALIPAY_MINIPROGRAM_PUB_KEY=app/Certs/Alipay/alipay_miniprogram_public_key.pem | ||
71 | +ALIPAY_MINIPROGRAM_PRIVATE_KEY=app/Certs/Alipay/alipay_miniprogram_private_key.pem | ||
72 | + | ||
73 | +SHOP_RANGE=5 | ||
74 | +SHOP_SEARCH_RANGE=20 | ||
75 | + | ||
76 | +DB_CONNECTION=mysql | ||
77 | +DB_HOST=127.0.0.1 | ||
78 | +DB_PORT=3306 | ||
79 | +DB_DATABASE=suishenwan | ||
80 | +DB_USERNAME=root | ||
81 | +DB_PASSWORD=123123 | ||
82 | + | ||
83 | +SESSION_DRIVER=database | ||
84 | +QUEUE_DRIVER=sync | ||
85 | + | ||
86 | +JWT_SECRET=ieButHiml02OljSkQV2sWcMA6gHcrVxb | ||
87 | + | ||
88 | +WECHAT_MINI_PROGRAM_ID=wx3185fb4a3633beb0 | ||
89 | +WECHAT_MINI_PROGRAM_SECRET=f60f2550f098eddfe4a8ff86bcf80fc0 | ||
90 | + | ||
91 | + | ||
92 | +TENCENT_MQ_HOST=https://cmq-queue-sh.api.qcloud.com | ||
93 | +TENCENT_MQ_SECRET_ID=AKIDQp9OXawOAqWAjCAr9LRRL9vcEj8QMkke | ||
94 | +TENCENT_MQ_SECRET_KEY=wnXDmFbqy1yoXhmldQ8kEf1GOPLBufMy | ||
95 | +TENCENT_OPEN_TOPIC=test-open |
.gitattributes
0 → 100644
.gitignore
0 → 100644
1 | +/node_modules | ||
2 | +/public/storage | ||
3 | +/public/hot | ||
4 | +/storage/*.key | ||
5 | +/vendor | ||
6 | +.idea | ||
7 | +Homestead.json | ||
8 | +Homestead.yaml | ||
9 | +.env | ||
10 | +.DS_Store | ||
11 | +Thumbs.db | ||
12 | +*.sublime-project | ||
13 | +*.sublime-workspace | ||
14 | +.project | ||
15 | +/nbproject | ||
16 | +_ide_helper.php | ||
17 | +composer.phar | ||
18 | +error.log | ||
19 | +Todo.rtf | ||
20 | +.vagrant | ||
21 | +/.vagrant | ||
22 | +npm-debug.log | ||
23 | +yarn-error.log | ||
24 | +/public/jpush.log |
.styleci.yml
0 → 100644
1 | +preset: laravel |
.travis.yml
0 → 100644
1 | +git: | ||
2 | + submodules: false | ||
3 | + | ||
4 | +language: php | ||
5 | + | ||
6 | +cache: | ||
7 | + directories: | ||
8 | + - vendor | ||
9 | + - $HOME/.composer/cache | ||
10 | +php: | ||
11 | + - 5.6 | ||
12 | + - 7.0 | ||
13 | + - 7.1 | ||
14 | + | ||
15 | +matrix: | ||
16 | + fast_finish: true | ||
17 | + include: | ||
18 | + - php: 7.0.12 # for coverage | ||
19 | + env: DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 EXEC_COVERAGE=true | ||
20 | + sudo: required | ||
21 | + dist: trusty | ||
22 | + exclude: | ||
23 | + - php: 5.6 | ||
24 | + env: DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 EXEC_COVERAGE=true | ||
25 | + - php: 7.0 | ||
26 | + env: DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 EXEC_COVERAGE=true | ||
27 | + - php: 7.1 | ||
28 | + env: DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 EXEC_COVERAGE=true | ||
29 | + allow_failures: | ||
30 | + - env: DB_DATABASE=sqlite | ||
31 | + - php: 7.0.12 # dist: trusty A dummy to run trusty, the test is not actually executed | ||
32 | + env: DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 EXEC_COVERAGE=true | ||
33 | + | ||
34 | +before_install: | ||
35 | + - if [[ "$DB_CONNECTION" == "pgsql" ]]; then psql -c "DROP DATABASE IF EXISTS boilerplate_test;" -U postgres; fi | ||
36 | + - if [[ "$DB_CONNECTION" == "pgsql" ]]; then psql -c "create database boilerplate_test;" -U postgres; fi | ||
37 | + - if [[ "$DB_CONNECTION" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS boilerplate_test;" -uroot; fi | ||
38 | + | ||
39 | +env: | ||
40 | + - DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 | ||
41 | + - DB_CONNECTION=pgsql DB_DATABASE=boilerplate_test DB_USERNAME=postgres DB_PASSWORD='' DB_PORT=5432 | ||
42 | + - DB_CONNECTION=mysql DB_DATABASE=boilerplate_test DB_USERNAME=root DB_PASSWORD='' DB_PORT=3306 EXEC_COVERAGE=true | ||
43 | + - DB_DATABASE=sqlite | ||
44 | + | ||
45 | +before_script: | ||
46 | + - if [[ $EXEC_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini ; fi | ||
47 | + - if [[ $EXEC_COVERAGE = 'true' ]]; then echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini ; fi | ||
48 | + - composer self-update || true | ||
49 | + - composer install --dev --no-interaction -o --no-scripts | ||
50 | + - composer run-script post-root-package-install | ||
51 | + - composer run-script post-create-project-cmd | ||
52 | + - composer run-script post-install-cmd | ||
53 | + | ||
54 | + | ||
55 | +script: | ||
56 | + - if [[ $EXEC_COVERAGE = 'true' ]]; then phpdbg -qrr ./vendor/bin/phpunit --coverage-clover=coverage.clover ; fi | ||
57 | + - if [[ $EXEC_COVERAGE != 'true' ]]; then ./vendor/bin/phpunit ; fi | ||
58 | + | ||
59 | +after_success: | ||
60 | + - if [[ $EXEC_COVERAGE = 'true' ]]; then php vendor/bin/coveralls -v -x coverage.clover ; fi | ||
61 | + | ||
62 | +after_failure: | ||
63 | + - cat storage/logs/laravel-`date +"%Y-%m-%d"`.log |
README.md
0 → 100644
1 | +#Suishengwan webservice project | ||
2 | + | ||
3 | +#### Init steps | ||
4 | +1. clone project | ||
5 | +``` | ||
6 | +git clone git@139.224.35.235:binqi.yuan/suishenwan_webservice.git | ||
7 | +``` | ||
8 | + | ||
9 | +2. Go to project directory, rename .env.example to .env | ||
10 | +``` | ||
11 | +mv .env.example .env | ||
12 | +``` | ||
13 | + | ||
14 | +3. run `composer update` | ||
15 | + | ||
16 | +4. modify .env file to change db connections | ||
17 | +``` | ||
18 | +DB_CONNECTION=mysql | ||
19 | +DB_HOST=127.0.0.1 | ||
20 | +DB_PORT=3306 | ||
21 | +DB_DATABASE=suishenwan | ||
22 | +DB_USERNAME=root | ||
23 | +DB_PASSWORD=123123 | ||
24 | +``` | ||
25 | + | ||
26 | +5. run migration to create the database tables | ||
27 | +``` | ||
28 | +php artisan migrate --seed | ||
29 | +``` | ||
30 | + | ||
31 | +6. use git subtree to use shared components | ||
32 | +``` | ||
33 | +//init remote | ||
34 | +git remote add modules git@139.224.35.235:binqi.yuan/suishenwan_module.git | ||
35 | +git remote add common git@139.224.35.235:binqi.yuan/suishenwan_common.git | ||
36 | +git remote add db git@139.224.35.235:binqi.yuan/suishenwan_database.git | ||
37 | +//subtree add modules | ||
38 | +git subtree add --prefix=app/Modules modules master --squash | ||
39 | +git subtree add --prefix=app/Common common master --squash | ||
40 | +git subtree add --prefix=database db master --squash | ||
41 | +``` | ||
42 | + | ||
43 | +7. use your own branch to start develop |
app/Certs/Alipay/alipay_mch_private_key.pem
0 → 100644
1 | +-----BEGIN RSA PRIVATE KEY----- | ||
2 | +MIIEpAIBAAKCAQEA4G2FytLndzQPksUkOlAtv1WbQYsg4M5YUcWOcFn/fJlGUNZrHWV3V+7zHP/tdm30ecaQbIodjhnzsQZ/TumF55x+4AeTeqLFuS0DELYkJn3rX/r3xNviaP+1Dkuqon/RgmAIzh0XAU2DJIZ6otooqhA2ZtonFl+T5xKH9bPBATOyupZQ1YGsS+dpGtt9Pk1zla5xTU70s7r6z5GnWKQTekGAgxYt2NT7zjEf/I8nfAmEXpvMwDOhZnNgav47lkDmogn+CXNdwMiOLGhl/G/ZdumgE9gk4QIBO/oQtrYtbNyZbCBg5eqZiN6cOXOmyfey3zYaI0TcQPte15oIHS35hQIDAQABAoIBABUqnzS64XO/qDxadYk+aKIkC8mJuqcZLwE/VajJBCyXNCeJoX6bRD853Rn+FUJXKniVvqdN+22civxGNZmWsrdebiTo8gLd+TH2ydQ4qX4r4BgkTlv1tQvcGhJoFobO8U6PiiUOX04TJmw6drSHSNCJSOg4aPlWOFfRyprkwi4/qbWloxuUSPQ0+zmdaGxaqbe79UKzigzqsVXVgSFopOZlB/OcDMWvvAd1zawW5CDteDhFomOB0zLgqsO+fTCgIVOvOpKP7TYu+uTL2eu9weRDrQhzsW3grhhPke2nTbNp78XW2mUdNld8fHib24frYsfW9718uddLyFoy5E2YjKECgYEA+/JE86Q+M7WjxwGeW6hQk2qAI526FRP0SeYajIBambLF7IniEMQaSwSSPZEqpeG2RZiG/bCyqzkb75g+vJ/APeF/ytJK+8FJcgQGUxaY4lOSPmgqa8y0XfOHbCqGvZ4IjC9B/fMBCGT1YFeTVDXa6NuFtK/xEHtoo80iUdwo4g0CgYEA5AnojBFbI757pyB16aQbhX1oVEkKbQuN8GH+/w639tD4WpWDHzREqceuU92jsy/REJAUSNJHvDSNwOg7qubgAO/l7bnZkz0Tdp9NdbHf2AhliK4sy8a5aBkfLVbpwh2eczdgLbAKL1NCE19Qw71eEzsTBzUZbOzkyvIlRVSTL1kCgYA99Y2ZcVnOs6vMRAyis9jk9/r9R0u85URdbBY5WVNumvVrv1j2EJP6wOwJ8gpP8xs1MFZ6SxsVWp0RJhq/nnXTggJAackA8r7SKEU558O/XRgI+ur7ycLNnBdAtZCfTx8BApozDrDBVLq3b7IOspPcUigmkGIzUHYiWk9HXGI9fQKBgQCkw2P6kC/By8ecIaAQiDo6YToYbA3UbBzKKoQL1Z6l/qbzDEQJL8LMyTHz9phox4vO48tEMmsSWQZy81jpSpdfFfaTpUzHTcHaW4+kEjkh5i82amKDebpMtJoKMFoFn1D0/nXHjQJO32FGjf/U7eYjDvPYqU0NnrxQxlSXm1wdQQKBgQC90UO5iFrrZK3I+dxygV+7k0Bjre5lBWG7IMKhAJgZj2NygpRJ/O3FVfbuhL4iCYBNTlb+pggp0y00g07n915j3aQ/aYk+HEoqE0pQ8zIGpIoTHM343GOH43yyeVe5/ID4K1bxCZ2H3jiNTM7UdO0YZjM3P4MYYQXU18IOlDExAQ== | ||
3 | +-----END RSA PRIVATE KEY----- |
app/Certs/Alipay/alipay_mch_public_key.pem
0 → 100644
1 | +-----BEGIN PUBLIC KEY----- | ||
2 | +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4G2FytLndzQPksUkOlAtv1WbQYsg4M5YUcWOcFn/fJlGUNZrHWV3V+7zHP/tdm30ecaQbIodjhnzsQZ/TumF55x+4AeTeqLFuS0DELYkJn3rX/r3xNviaP+1Dkuqon/RgmAIzh0XAU2DJIZ6otooqhA2ZtonFl+T5xKH9bPBATOyupZQ1YGsS+dpGtt9Pk1zla5xTU70s7r6z5GnWKQTekGAgxYt2NT7zjEf/I8nfAmEXpvMwDOhZnNgav47lkDmogn+CXNdwMiOLGhl/G/ZdumgE9gk4QIBO/oQtrYtbNyZbCBg5eqZiN6cOXOmyfey3zYaI0TcQPte15oIHS35hQIDAQAB | ||
3 | +-----END PUBLIC KEY----- |
1 | +-----BEGIN RSA PRIVATE KEY----- | ||
2 | +MIIEpAIBAAKCAQEAx/lG8E1hDTDEFoYQtJMjCO0XHoaphq5MFv1WZtBvo6vJ4GSjwkF8z9yS2s54z/oLbR2m0ddo0Q8+rv2KTCBhvZz5zd/72Ynwu8WXemgGnHyhjyq13Q4gkcymukonP0XECQvlVCr3pu3YLv0uVzC7B+zTby5rdOqW9DgwfkS8QWHa3HonBxg1dknhAmS3Rl43sWPv71C5V9O24Ud865PbhMP3kPnIeNXkngQHFfq8LRgKNr7YK8Cww4AgN2wUenGLIZrnYl2rXTHTNcjFHqvUb/egQrjM+CxKoKqNnXRPpz+0DIa66Vh46uRr+vJYcayptBk42HYF8lWKbtzfGp8F0QIDAQABAoIBAQCTYNgzShP40LPzlaLCMp5jebjMOpq+M77IQrVm2L8udPE3e3RlOjZuSzXAJONNBA9fv7aueH87dGzSMvG14TenswU4AZdvYAYXnSxifkBBHGlFRkj6PesrCRTnvrbmHti3ghjlyzTxxeDJ4LZCdBujX5sEGcYASNQv8SlsJeRImjRagDEOuvRFr08iDvooISEXgG7TfZStm2b32x4vOVRyoSmnUSgujr2xmX6zLQva0QDgCrO9oiNkGCRZOrsRyuu7RHpnKKFb/Aermo3ne8Pn5oBYD6Xyop9vcRsCkjwlrTapXpvcXnxMQE2YQTJkrTaj7rj9xt2oxtGWtf/iG/cxAoGBAOQSVmzX3/Mjw5xoU2LO5O+70yVAqEuqf6AV6csJXzqfHqlTp4BJMryLQqXJ2lXCkNHJdhslwy5Hvh2NDPXLGIt7fjPrB+ghXyi05N0i7SzRhxqBYbDgxkXlpeOHwjStvOIl3PG7f/ri0XJUHnJ895BWUFIFMdVYjUQcFy+oYVPXAoGBAOB2Hidf2rnvHbN/ARbG6sM9HD0KON5n+upRqYT3xPcp1xrYn7BY5lyg2P8HKV+Gzjk/iPTzDEf/7SFrr4MGlBk0mg18nn/7POJOVe/8iqGUFK3f9E2gKXqo6Ouz+Xlh5YzmXBQLbJ50TRkcWa7CnKh8sDgQbnegGP6y5iFLS76XAoGAAxVUYchRWMIlBNpMNkvBwJPzeM909wDpFMr3DC2mQe6gxX1CCHP04aOoVQFzmDE3L/7fP+K0zs1dfpzHjhMe09Ppkt4cj0DUPoKjjXHJbw+uGeeh4HhJdexy366YK4olwZDteb8lLckfN8J3Xujdl+/yygkT8WRvFHqkvZozJqUCgYAtaji3psFOlX7g7nV98klVr2ujPgo7lbZC6rrt2GPVznVjTSkiORqC61h8YSqR1WisVJqVVQfLGZEVDgC49f/JCceRqwE2y9KJx2fD4sj54Eg+1e1MN3etBbf62LNFR/V2CLXgqF8VwFpJFl9e6Klhvbi53zk6ov3rqq69VcrBiQKBgQDQySqesjCSvhcG3m8abK283JiIgs+og5iJHE1EeLDKJJViUX0xLOKhQIq7NgutVJ/lKehwaSqmULxc6vWLn717VyJ+GVqCeszyHALOpNvjOMgcQTU08ZshNPgoCjt18GhQ5ZruietF2OvzuHkVHLg+MnHrKn01HyEhB0NU/bY19A== | ||
3 | +-----END RSA PRIVATE KEY----- |
1 | +-----BEGIN PUBLIC KEY----- | ||
2 | +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx/lG8E1hDTDEFoYQtJMjCO0XHoaphq5MFv1WZtBvo6vJ4GSjwkF8z9yS2s54z/oLbR2m0ddo0Q8+rv2KTCBhvZz5zd/72Ynwu8WXemgGnHyhjyq13Q4gkcymukonP0XECQvlVCr3pu3YLv0uVzC7B+zTby5rdOqW9DgwfkS8QWHa3HonBxg1dknhAmS3Rl43sWPv71C5V9O24Ud865PbhMP3kPnIeNXkngQHFfq8LRgKNr7YK8Cww4AgN2wUenGLIZrnYl2rXTHTNcjFHqvUb/egQrjM+CxKoKqNnXRPpz+0DIa66Vh46uRr+vJYcayptBk42HYF8lWKbtzfGp8F0QIDAQAB | ||
3 | +-----END PUBLIC KEY----- |
app/Certs/Alipay/alipay_public_key.pem
0 → 100644
1 | +-----BEGIN PUBLIC KEY----- | ||
2 | +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2J8XSVliMFk51D6BTB2otLINtmIJYWjgDzOhSJbENz8zevWbMFndLfbkBdutmHrlsZM1wSn7tR3wugs0px1EaX9c9hBuET+7fIlya8sc7iUaJiI+S5sL60vK2A5yM8Rlx2yJNg4MYgMjty0wFogQd2V9aCThriW796rYLuqIHrgt5DWSaBYYuvZDQjYdvnd1p4agJOEux1LfVjtkcgu9UBfwg5oWL5RZpWiI5tR7MG0JOzZbrAY+EPOtOnh5tWoEjOZiQD6E0XcmOO4jOxI7x5DJ2om+AHHU3cpVUqRt/F6tKbnxuv8R406ZQZyJ5omK3/8G+ibb8keYuv+qMzHANwIDAQAB | ||
3 | +-----END PUBLIC KEY----- |
app/Certs/Wechat/apiclient_cert.pem
0 → 100644
1 | +-----BEGIN CERTIFICATE----- | ||
2 | +MIIEbDCCA9WgAwIBAgIEAWJK2zANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC | ||
3 | +Q04xEjAQBgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNV | ||
4 | +BAoTB1RlbmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEf | ||
5 | +MB0GCSqGSIb3DQEJARYQbW1wYXltY2hAdGVuY2VudDAeFw0xNzA4MDcwOTAwNDZa | ||
6 | +Fw0yNzA4MDUwOTAwNDZaMIGbMQswCQYDVQQGEwJDTjESMBAGA1UECBMJR3Vhbmdk | ||
7 | +b25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UEChMHVGVuY2VudDEOMAwGA1UE | ||
8 | +CxMFTU1QYXkxMDAuBgNVBAMUJ+iLj+W3numaj+i6q+eOqeS/oeaBr+aKgOacr+ac | ||
9 | +iemZkOWFrOWPuDERMA8GA1UEBBMINDEyOTEyMTcwggEiMA0GCSqGSIb3DQEBAQUA | ||
10 | +A4IBDwAwggEKAoIBAQDeUEFC0H3NiPALgWZQGtAEFoyiAMEcGKWKxDAXA+7RTzkH | ||
11 | +Y6rRqWa4UtmLn+y2Dq3Bqj0JV9/hpxH4XDGmyVEPoeX1vrvjY+hZa5vsHo5iAowC | ||
12 | ++/5tfbSK0MCIqLVu32RUL/2XNKzu1uI9qJCyG5S5xviwY+LUsIiQVSYS68xxPmQi | ||
13 | +UvB/Si7nPVu8flQp/CErGj67+UnfRstzdlXmIedVZI2B/zDY36GWz99OcC1vKAoH | ||
14 | +1Qyr0djSPKUjBW728SgKgt7koS1DV4tQdd+Z3d0JUMaf1xC3HQgYxrIsOAo/mRki | ||
15 | +fCvRG19WB6UgQn57pAPQ1aRmc8uHoc4K0t5PG3z3AgMBAAGjggFGMIIBQjAJBgNV | ||
16 | +HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh0iQ0VTLUNBIEdlbmVyYXRlIENlcnRpZmlj | ||
17 | +YXRlIjAdBgNVHQ4EFgQUkwjPtBG/QHSUDjRnzQs7jkYgkHwwgb8GA1UdIwSBtzCB | ||
18 | +tIAUPgUm9iJitBVbiM1kfrDUYqflhnShgZCkgY0wgYoxCzAJBgNVBAYTAkNOMRIw | ||
19 | +EAYDVQQIEwlHdWFuZ2RvbmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQKEwdU | ||
20 | +ZW5jZW50MQwwCgYDVQQLEwNXWEcxEzARBgNVBAMTCk1tcGF5bWNoQ0ExHzAdBgkq | ||
21 | +hkiG9w0BCQEWEG1tcGF5bWNoQHRlbmNlbnSCCQC7VJcrvADoVzAOBgNVHQ8BAf8E | ||
22 | +BAMCBsAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEA | ||
23 | +NkWBjd8qNtg5LT8u+lns5kmoqMgJmPqWsLkeAdDzGQgk0umVIivnbvjBK9gyQDo8 | ||
24 | +M3uQjHDOeoL9kpYQoZCzcC/0NqMluXjmvfXiarc1lv2RYu4nNoUVp4ix/15dFhML | ||
25 | +pS65pTZ3LXXDigY76nFOu6XztJNvylnDZ/c7nejsC3g= | ||
26 | +-----END CERTIFICATE----- |
app/Certs/Wechat/apiclient_key.pem
0 → 100644
1 | +-----BEGIN PRIVATE KEY----- | ||
2 | +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDeUEFC0H3NiPAL | ||
3 | +gWZQGtAEFoyiAMEcGKWKxDAXA+7RTzkHY6rRqWa4UtmLn+y2Dq3Bqj0JV9/hpxH4 | ||
4 | +XDGmyVEPoeX1vrvjY+hZa5vsHo5iAowC+/5tfbSK0MCIqLVu32RUL/2XNKzu1uI9 | ||
5 | +qJCyG5S5xviwY+LUsIiQVSYS68xxPmQiUvB/Si7nPVu8flQp/CErGj67+UnfRstz | ||
6 | +dlXmIedVZI2B/zDY36GWz99OcC1vKAoH1Qyr0djSPKUjBW728SgKgt7koS1DV4tQ | ||
7 | +dd+Z3d0JUMaf1xC3HQgYxrIsOAo/mRkifCvRG19WB6UgQn57pAPQ1aRmc8uHoc4K | ||
8 | +0t5PG3z3AgMBAAECggEAIepAan8AEjEH3dl50FKm1VjTT4up6i1gY9EWPQyejFP3 | ||
9 | +sUblMmMThp8tDP3y0LtgiqD7+sbrIrOoLCl0catYsHfUay8T3tbJBYtDGDx5ID6f | ||
10 | +OX1UDUQWHO9H0BFczHNMDQPdPgoNL8qcbSegG2vVvpm6Kr6yRhxAWTSEQHK0l7nS | ||
11 | +F30WM0uTtu4iaJi71MCvZZSHiRkr1hJettfeECJYZoCxxKpI/+DXV2bi1xVbyBTl | ||
12 | +k4/n6sBV7lSS5ELsm4RGkV9YIMuHmjeV0qGn4pnvt79tCK72KAP5a06OorrVHUqH | ||
13 | +IKymJqi8MTPceI4h2D2Q3XN0YUUjAsko2bg54kQBgQKBgQD4dck0IizWQdu2fb3W | ||
14 | +n/42I7XEA9YtgXuiQRAnSgzTi6Yk98vcVyDDUi4xfw8JzxvPSpIlItJVEEiQSJOt | ||
15 | +9nK6VXW5ZAGiG6C2RKrtZ4bWEYmp57C0mu3Q3X7NBez/mRkvkc2p64ZN4o9p4pBL | ||
16 | +NKow0EFH+0LaTVHkgef39Qh91wKBgQDlD1f3p8jtClIYMYKrLjW7wUmd2+o+VpFT | ||
17 | +Dkfx39Kx9GzS0UdpwUAXdrWX8a9q33raMj0hih5GSc0hYOA+TVZ7feZxwDwvfsra | ||
18 | +uY/9Z7ShoYKs35Tz0i6quqQtbOz47bDo63uvivf8C/juXR+tdJFt8Dw7he9v7IT5 | ||
19 | +sduzVXfV4QKBgQCGJFmf+v+IIgB0k4jF8pV2N2twS737zZepb0VAYRtxr0jhVqPK | ||
20 | +74Nx0NG9yWKeIiJalWE4CYfTgzoaJAUPfCpO7crkb9jt48qt/X7nM+i5dLiFceCW | ||
21 | +cbsJ9Dv8h0GAcfEGHMsT/WQCctqJCVhsMh/cwOMt8LsUT4ByRayu061k+wKBgQC0 | ||
22 | +Pz22uUZoGS3+sb8kWwmXhIMcgHg0s8RJujws/jb7J98Wie6LLrHzhMtjFKE4FUHE | ||
23 | +P7JRGTG3l82ejXAINq1uIeVb76yspzaTpV/ERX4jjkeZJ5s7vlJQsOwOft9/BvOm | ||
24 | +Zd9/hHid0wIA+DC8OrVR8LBFGqEOzuzY2/eJiCDzoQKBgQDmPl4D02GIeORgO46R | ||
25 | +/SVVMdK4/wz9OhwaWX2NNkHi6d5YZjR+e0w7XmmmT1n8C+Dcf0i3EdSCH2ci9kYU | ||
26 | +dQ5A0wHPVYX1tw6yeqQYXYyfVHwcLCZO4sTJXUwD2OZ4AncjhI3PG1YnhJUov0Y8 | ||
27 | +dVXi8bkgyP/Wo47YevasN7t2qQ== | ||
28 | +-----END PRIVATE KEY----- |
app/Common/Alipay.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 13/03/2017 | ||
6 | + * Time: 1:40 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | + | ||
12 | +/** | ||
13 | + * Class Alipay | ||
14 | + * @package App\Common | ||
15 | + */ | ||
16 | +/** | ||
17 | + * Class Alipay | ||
18 | + * @package App\Common | ||
19 | + */ | ||
20 | + | ||
21 | +use App\Common\Enums\AlipayLoginType; | ||
22 | +use App\Common\Util\OrderUtil; | ||
23 | +use Illuminate\Support\Facades\Log; | ||
24 | + | ||
25 | +/** | ||
26 | + * Class Alipay | ||
27 | + * @package App\Common | ||
28 | + */ | ||
29 | +class Alipay | ||
30 | +{ | ||
31 | + /** | ||
32 | + * order Id | ||
33 | + * @var | ||
34 | + */ | ||
35 | + private $order_id; | ||
36 | + | ||
37 | + /** | ||
38 | + * Order price | ||
39 | + * @var | ||
40 | + */ | ||
41 | + private $price; | ||
42 | + | ||
43 | + /** | ||
44 | + * pay description | ||
45 | + * @var | ||
46 | + */ | ||
47 | + private $body; | ||
48 | + | ||
49 | + /** | ||
50 | + * @var | ||
51 | + */ | ||
52 | + private $subject; | ||
53 | + | ||
54 | + /** | ||
55 | + * Callback Url | ||
56 | + * @var | ||
57 | + */ | ||
58 | + private $call_back_url; | ||
59 | + | ||
60 | + /** | ||
61 | + * @var | ||
62 | + */ | ||
63 | + private $refund_fee; | ||
64 | + | ||
65 | + /** | ||
66 | + * @var | ||
67 | + */ | ||
68 | + private $refund_id; | ||
69 | + | ||
70 | + /** | ||
71 | + * @var | ||
72 | + */ | ||
73 | + private $op_user_id; | ||
74 | + | ||
75 | + /** | ||
76 | + * @var | ||
77 | + */ | ||
78 | + private $pay_no; | ||
79 | + | ||
80 | + /** | ||
81 | + * WechatPay constructor. | ||
82 | + * @param $order_id | ||
83 | + * @param $price | ||
84 | + * @param $body | ||
85 | + * @param $call_back_url | ||
86 | + */ | ||
87 | + public function __construct($order_id="", $price=0, $body="", $call_back_url="", $subject="") | ||
88 | + { | ||
89 | + $this->order_id = $order_id; | ||
90 | + $this->price = $price; | ||
91 | + $this->body = $body; | ||
92 | + $this->call_back_url = $call_back_url; | ||
93 | + $this->subject = $subject; | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * @param mixed $refund_fee | ||
98 | + */ | ||
99 | + public function setRefundFee($refund_fee) | ||
100 | + { | ||
101 | + $this->refund_fee = $refund_fee; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * @param mixed $op_user_id | ||
106 | + */ | ||
107 | + public function setOpUserId($op_user_id) | ||
108 | + { | ||
109 | + $this->op_user_id = $op_user_id; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * @param mixed $refund_id | ||
114 | + */ | ||
115 | + public function setRefundId($refund_id) | ||
116 | + { | ||
117 | + $this->refund_id = $refund_id; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * @param mixed $pay_no | ||
122 | + */ | ||
123 | + public function setPayNo($pay_no) | ||
124 | + { | ||
125 | + $this->pay_no = $pay_no; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * @param $success | ||
130 | + * @param $error_messge | ||
131 | + * @param string $payInfo | ||
132 | + * @return array | ||
133 | + */ | ||
134 | + private function response($success, $error_messge, $payInfo="") | ||
135 | + { | ||
136 | + $result = array('success'=>$success, 'error_message'=>$error_messge, 'payInfo'=>$payInfo); | ||
137 | + | ||
138 | + return $result; | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * @param $type | ||
143 | + * @return \AopClient | ||
144 | + */ | ||
145 | + private function getAopClient($type = AlipayLoginType::APP) | ||
146 | + { | ||
147 | + $aop = new \AopClient(); | ||
148 | + $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; | ||
149 | + $aop->appId = $type == AlipayLoginType::APP ? config('constants.alipay.app_id') : config('constants.alipay.app_miniprogram_id'); | ||
150 | + $aop->rsaPrivateKeyFilePath = $type == AlipayLoginType::APP ? config('constants.alipay.alipay_mch_private_key') : config('constants.alipay.alipay_miniprogram_private_key'); | ||
151 | + $aop->format = "json"; | ||
152 | + $aop->charset = "UTF-8"; | ||
153 | + $aop->signType = "RSA2"; | ||
154 | + $aop->alipayPublicKey=config('constants.alipay.alipay_pub_key'); | ||
155 | + | ||
156 | + return $aop; | ||
157 | + } | ||
158 | + | ||
159 | + /** | ||
160 | + * 获取第三方登录字串 | ||
161 | + * | ||
162 | + * @return string | ||
163 | + */ | ||
164 | + public function getAppAuthCode() | ||
165 | + { | ||
166 | + $params = array( | ||
167 | + "apiname" => 'com.alipay.account.auth', | ||
168 | + "method" => 'alipay.open.auth.sdk.code.get', | ||
169 | + "app_id"=> config('constants.alipay.app_id'), | ||
170 | + "app_name"=>'mc', | ||
171 | + "biz_type" => 'openservice', | ||
172 | + 'pid' => '2088721389489661', | ||
173 | + 'product_id' => 'APP_FAST_LOGIN', | ||
174 | + 'scope' => 'kuaijie', | ||
175 | + 'target_id' => OrderUtil::generateCosumeOrderId(), | ||
176 | + "auth_type" => 'AUTHACCOUNT', | ||
177 | + "sign_type" => 'RSA2' | ||
178 | + ); | ||
179 | + | ||
180 | + $aop = $this->getAopClient(); | ||
181 | + $sign = $aop->generateSign($params, 'RSA2'); | ||
182 | + $params['sign'] = $sign; | ||
183 | + | ||
184 | + return http_build_query($params); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * 无线账户授权 | ||
189 | + * | ||
190 | + * @param $code | ||
191 | + * @param $type | ||
192 | + * @return bool|mixed|\SimpleXMLElement | ||
193 | + */ | ||
194 | + public function alipaySystemAccountAuth($code, $type = AlipayLoginType::APP) | ||
195 | + { | ||
196 | + $aop = $this->getAopClient($type); | ||
197 | + | ||
198 | + $request = new \AlipaySystemOauthTokenRequest(); | ||
199 | + $request->setCode($code); | ||
200 | + $request->setGrantType('authorization_code'); | ||
201 | + | ||
202 | + $response = $aop->execute($request); | ||
203 | + | ||
204 | + Log::info('response is $response!'); | ||
205 | + | ||
206 | + if (isset($response->alipay_system_oauth_token_response)) | ||
207 | + { | ||
208 | + return ['access_token' => $response->alipay_system_oauth_token_response->access_token, 'user_id'=> $response->alipay_system_oauth_token_response->user_id]; | ||
209 | + } | ||
210 | + | ||
211 | + return false; | ||
212 | + } | ||
213 | + | ||
214 | + /** | ||
215 | + * 用户信息共享 | ||
216 | + * | ||
217 | + * @param $access_token | ||
218 | + * @param $type | ||
219 | + * @return bool|mixed|\SimpleXMLElement | ||
220 | + */ | ||
221 | + public function alipayUserInfoShare($access_token, $type = AlipayLoginType::APP) | ||
222 | + { | ||
223 | + $aop = $this->getAopClient($type); | ||
224 | + $request = new \AlipayUserInfoShareRequest(); | ||
225 | + | ||
226 | + $response = $aop->execute($request, $access_token); | ||
227 | + | ||
228 | + Log::info('response is $response!'); | ||
229 | + | ||
230 | + if (isset($response->alipay_user_info_share_response)) | ||
231 | + { | ||
232 | + return (array)$response->alipay_user_info_share_response; | ||
233 | + } | ||
234 | + | ||
235 | + return false; | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * @param $property_id | ||
240 | + * @return array|bool | ||
241 | + */ | ||
242 | + public function alipayTradePrecreate($property_id) | ||
243 | + { | ||
244 | + $aop = $this->getAopClient(); | ||
245 | + | ||
246 | + $bizContent = $this->getPrecreateAppBizContent($property_id); | ||
247 | + $request = new \AlipayTradePrecreateRequest(); | ||
248 | + $request->setNotifyUrl($this->call_back_url); | ||
249 | + $request->setBizContent($bizContent); | ||
250 | + | ||
251 | + $response = $aop->execute($request); | ||
252 | + if (isset($response->alipay_trade_precreate_response)) | ||
253 | + { | ||
254 | + return (array)$response->alipay_trade_precreate_response; | ||
255 | + } | ||
256 | + | ||
257 | + return false; | ||
258 | + } | ||
259 | + | ||
260 | + /** | ||
261 | + * @param $property_id | ||
262 | + * | ||
263 | + * @return string | ||
264 | + */ | ||
265 | + private function getPrecreateAppBizContent($property_id) | ||
266 | + { | ||
267 | + $param = array( | ||
268 | + "out_trade_no"=>$this->order_id, | ||
269 | + "subject" => "优卡充充值", | ||
270 | + 'store_id' => $property_id, | ||
271 | + "total_amount" => $this->price, | ||
272 | + "timeout_express" => "10m", | ||
273 | + ); | ||
274 | + | ||
275 | + return json_encode($param); | ||
276 | + } | ||
277 | + | ||
278 | + /** | ||
279 | + * @return mixed | ||
280 | + */ | ||
281 | + public function getUnifiedOrderInfo() | ||
282 | + { | ||
283 | + $aop = $this->getAopClient(); | ||
284 | + $request = new \AlipayTradeAppPayRequest(); | ||
285 | + | ||
286 | + $bizContent = $this->getAppBizContent(); | ||
287 | + $request->setNotifyUrl($this->call_back_url); | ||
288 | + $request->setBizContent($bizContent); | ||
289 | + | ||
290 | + $response = $aop->sdkExecute($request); | ||
291 | + return $this->response("success", "", $response); | ||
292 | + } | ||
293 | + | ||
294 | + /** | ||
295 | + * @return string | ||
296 | + */ | ||
297 | + private function getAppBizContent() | ||
298 | + { | ||
299 | + $param = array( | ||
300 | + "body" => $this->body, | ||
301 | + "subject" => $this->body, | ||
302 | + "out_trade_no"=>$this->order_id, | ||
303 | + "timeout_express" => "40m", | ||
304 | + "total_amount" => $this->price, | ||
305 | + "product_code" => "QUICK_MSECURITY_PAY" | ||
306 | + ); | ||
307 | + | ||
308 | + return json_encode($param); | ||
309 | + } | ||
310 | + | ||
311 | + | ||
312 | + /** | ||
313 | + * @param $input | ||
314 | + * @return bool | ||
315 | + */ | ||
316 | + public function checkSign($input) | ||
317 | + { | ||
318 | + $aop = new \AopClient(); | ||
319 | + $aop->alipayPublicKey=config('constants.alipay.alipay_pub_key'); | ||
320 | + $flag = $aop->rsaCheckV1($input, config('constants.alipay.alipay_pub_key'), "RSA2"); | ||
321 | + | ||
322 | + return $flag; | ||
323 | + } | ||
324 | + | ||
325 | + /** | ||
326 | + * | ||
327 | + */ | ||
328 | + public function refund() | ||
329 | + { | ||
330 | + $aop = new \AopClient(); | ||
331 | + $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; | ||
332 | + $aop->appId = config('constants.alipay.app_id'); | ||
333 | + $aop->rsaPrivateKeyFilePath = config('constants.alipay.alipay_mch_private_key'); | ||
334 | + $aop->alipayPublicKey= config('constants.alipay.alipay_pub_key'); | ||
335 | + $aop->postCharset='UTF-8'; | ||
336 | + $aop->format='json'; | ||
337 | + $request = new \AlipayTradeRefundRequest(); | ||
338 | + | ||
339 | + $bizContent = $this->getRefundBizContent(); | ||
340 | + $request->setBizContent($bizContent); | ||
341 | + $response = $aop->execute ( $request); | ||
342 | + | ||
343 | + $this->response(true, "", htmlspecialchars($response)); | ||
344 | + } | ||
345 | + | ||
346 | + /** | ||
347 | + * @return string | ||
348 | + */ | ||
349 | + private function getRefundBizContent() | ||
350 | + { | ||
351 | + $param = array( | ||
352 | + "out_trade_no" => $this->order_id, | ||
353 | + "trade_no" => $this->pay_no, | ||
354 | + "refund_amount"=>$this->refund_fee, | ||
355 | + "refund_reason" => "refund", | ||
356 | + "out_request_no" => $this->refund_id, | ||
357 | + "operator_id" => "OP001", | ||
358 | + "store_id" => "NJ_S_001", | ||
359 | + "terminal_id" => "NJ_T_001" | ||
360 | + ); | ||
361 | + | ||
362 | + return json_encode($param); | ||
363 | + } | ||
364 | +} |
app/Common/Amap.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 25/04/2017 | ||
6 | + * Time: 11:47 AM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | + | ||
12 | +class Amap | ||
13 | +{ | ||
14 | + public static function getAdCodeUsingLatAndLng($lat, $lng) | ||
15 | + { | ||
16 | + $url = config('constants.amap.url').'?key='.config('constants.amap.key').'&location='.$lng.','.$lat; | ||
17 | + $result = Http::Get($url); | ||
18 | + | ||
19 | + $result = json_decode($result, true); | ||
20 | + | ||
21 | + return $result['regeocode']['addressComponent']['adcode']; | ||
22 | + } | ||
23 | +} | ||
24 | + |
app/Common/Byte.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 20/03/2017 | ||
6 | + * Time: 2:17 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | + | ||
12 | +class Byte | ||
13 | +{ | ||
14 | + /** | ||
15 | + * 转换一个String字符串为byte数组(10进制) | ||
16 | + * @param $str | ||
17 | + * @return array | ||
18 | + */ | ||
19 | + public static function getBytes_10($str) { | ||
20 | + $len = strlen($str); | ||
21 | + $bytes = array(); | ||
22 | + for($i=0;$i<$len;$i++) { | ||
23 | + if(ord($str[$i]) >= 128){ | ||
24 | + $byte = ord($str[$i]) - 256; | ||
25 | + }else{ | ||
26 | + $byte = ord($str[$i]); | ||
27 | + } | ||
28 | + $bytes[] = $byte ; | ||
29 | + } | ||
30 | + return $bytes; | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | + /** | ||
35 | + * 转换一个String字符串为byte数组(16进制) | ||
36 | + * @param $str | ||
37 | + * @return array | ||
38 | + */ | ||
39 | + public static function getBytes_16($str) { | ||
40 | + | ||
41 | + | ||
42 | + $len = strlen($str); | ||
43 | + $bytes = array(); | ||
44 | + for($i=0;$i<$len;$i++) { | ||
45 | + if(ord($str[$i]) >= 128){ | ||
46 | + $byte = ord($str[$i]) - 256; | ||
47 | + }else{ | ||
48 | + $byte = ord($str[$i]); | ||
49 | + } | ||
50 | + $bytes[] = "0x".dechex($byte) ; | ||
51 | + } | ||
52 | + return $bytes; | ||
53 | + } | ||
54 | + | ||
55 | + | ||
56 | + /** | ||
57 | + * 转换一个String字符串为byte数组(2进制) | ||
58 | + * @param $str | ||
59 | + * @return array | ||
60 | + */ | ||
61 | + public static function StrToBin($str){ | ||
62 | + //1.列出每个字符 | ||
63 | + $arr = preg_split('/(?<!^)(?!$)/u', $str); | ||
64 | + //2.unpack字符 | ||
65 | + foreach($arr as &$v){ | ||
66 | + $temp = unpack('H*', $v); | ||
67 | + $v = base_convert($temp[1], 16, 2); | ||
68 | + unset($temp); | ||
69 | + } | ||
70 | + | ||
71 | + return $arr; | ||
72 | + } | ||
73 | + | ||
74 | + | ||
75 | + /** | ||
76 | + * 转换一个byte数组为String(2进制) | ||
77 | + * @param $str 需要转换的字符串 | ||
78 | + * @return string | ||
79 | + */ | ||
80 | + function BinToStr($str){ | ||
81 | + $arr = explode(' ', $str); | ||
82 | + foreach($arr as &$v){ | ||
83 | + $v = pack("H".strlen(base_convert($v, 2, 16)), base_convert($v, 2, 16)); | ||
84 | + } | ||
85 | + | ||
86 | + return $v; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * 将字节数组转化为String类型的数据 | ||
91 | + * @param $bytes | ||
92 | + * @return string | ||
93 | + */ | ||
94 | + public static function toStr($bytes) { | ||
95 | + $str = ''; | ||
96 | + foreach($bytes as $ch) { | ||
97 | + $str .= chr($ch); | ||
98 | + } | ||
99 | + | ||
100 | + | ||
101 | + return $str; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * 转换一个int为byte数组 | ||
106 | + * @param $val | ||
107 | + * @return array | ||
108 | + */ | ||
109 | + | ||
110 | + public static function integerToBytes($val) { | ||
111 | + $byt = array(); | ||
112 | + $byt[0] = ($val & 0xff); | ||
113 | + $byt[1] = ($val >> 8 & 0xff); | ||
114 | + $byt[2] = ($val >> 16 & 0xff); | ||
115 | + $byt[3] = ($val >> 24 & 0xff); | ||
116 | + return $byt; | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * 从字节数组中指定的位置读取一个Integer类型的数据 | ||
121 | + * @param $bytes 字节数组 | ||
122 | + * @param $position 指定的开始位置 | ||
123 | + * @return 一个Integer类型的数据 | ||
124 | + */ | ||
125 | + | ||
126 | + public static function bytesToInteger($bytes, $position) { | ||
127 | + $val = 0; | ||
128 | + $val = $bytes[$position + 3] & 0xff; | ||
129 | + $val <<= 8; | ||
130 | + $val |= $bytes[$position + 2] & 0xff; | ||
131 | + $val <<= 8; | ||
132 | + $val |= $bytes[$position + 1] & 0xff; | ||
133 | + $val <<= 8; | ||
134 | + $val |= $bytes[$position] & 0xff; | ||
135 | + return $val; | ||
136 | + } | ||
137 | + | ||
138 | + | ||
139 | + /** | ||
140 | + * 转换一个short字符串为byte数组 | ||
141 | + * @param $val | ||
142 | + * @return array | ||
143 | + */ | ||
144 | + | ||
145 | + public static function shortToBytes($val) { | ||
146 | + $byt = array(); | ||
147 | + $byt[0] = ($val & 0xff); | ||
148 | + $byt[1] = ($val >> 8 & 0xff); | ||
149 | + return $byt; | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * 从字节数组中指定的位置读取一个Short类型的数据。 | ||
154 | + * @param $bytes | ||
155 | + * @param $position | ||
156 | + * @return short | ||
157 | + */ | ||
158 | + public static function bytesToShort($bytes, $position) { | ||
159 | + $val = 0; | ||
160 | + $val = $bytes[$position + 1] & 0xFF; | ||
161 | + $val = $val << 8; | ||
162 | + $val |= $bytes[$position] & 0xFF; | ||
163 | + return $val; | ||
164 | + } | ||
165 | + | ||
166 | +} |
app/Common/CropAvatar.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 24/02/2017 | ||
6 | + * Time: 5:11 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | + | ||
12 | +class CropAvatar { | ||
13 | + private $src; | ||
14 | + private $data; | ||
15 | + private $file; | ||
16 | + private $dst; | ||
17 | + private $type; | ||
18 | + private $extension; | ||
19 | + private $msg; | ||
20 | + private $imgWidth; | ||
21 | + private $imgHeight; | ||
22 | + | ||
23 | + function __construct($src, $data, $file, $imgWidth, $imgHeight) { | ||
24 | + $this ->imgWidth = $imgWidth; | ||
25 | + $this ->imgHeight = $imgHeight; | ||
26 | + $this -> setSrc($src); | ||
27 | + $this -> setData($data); | ||
28 | + $this -> setFile($file); | ||
29 | + $this -> crop($this -> src, $this -> dst, $this -> data); | ||
30 | + } | ||
31 | + | ||
32 | + private function setSrc($src) { | ||
33 | + if (!empty($src)) { | ||
34 | + $type = exif_imagetype($src); | ||
35 | + | ||
36 | + if ($type) { | ||
37 | + $this -> src = $src; | ||
38 | + $this -> type = $type; | ||
39 | + $this -> extension = image_type_to_extension($type); | ||
40 | + $this -> setDst(); | ||
41 | + } | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | + private function setData($data) { | ||
46 | + if (!empty($data)) { | ||
47 | + $this -> data = json_decode(stripslashes($data)); | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + private function setFile($file) { | ||
52 | + $errorCode = $file['error']; | ||
53 | + | ||
54 | + if ($errorCode === UPLOAD_ERR_OK) { | ||
55 | + $type = exif_imagetype($file['tmp_name']); | ||
56 | + | ||
57 | + if ($type) { | ||
58 | + $extension = image_type_to_extension($type); | ||
59 | + $src = config("constants.common.temp_file_location") . date('YmdHis') . '.original' . $extension; | ||
60 | + | ||
61 | + if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) { | ||
62 | + | ||
63 | + if (file_exists($src)) { | ||
64 | + unlink($src); | ||
65 | + } | ||
66 | + | ||
67 | + $result = move_uploaded_file($file['tmp_name'], $src); | ||
68 | + | ||
69 | + if ($result) { | ||
70 | + $this -> src = $src; | ||
71 | + $this -> type = $type; | ||
72 | + $this -> extension = $extension; | ||
73 | + $this -> setDst(); | ||
74 | + } else { | ||
75 | + $this -> msg = 'Failed to save file'; | ||
76 | + } | ||
77 | + } else { | ||
78 | + $this -> msg = 'Please upload image with the following types: JPG, PNG, GIF'; | ||
79 | + } | ||
80 | + } else { | ||
81 | + $this -> msg = 'Please upload image file'; | ||
82 | + } | ||
83 | + } else { | ||
84 | + $this -> msg = $this -> codeToMessage($errorCode); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + private function setDst() { | ||
89 | + $this -> dst = config("constants.common.temp_file_location") . date('YmdHis') . '.png'; | ||
90 | + } | ||
91 | + | ||
92 | + private function crop($src, $dst, $data) { | ||
93 | + if (!empty($src) && !empty($dst) && !empty($data)) { | ||
94 | + switch ($this -> type) { | ||
95 | + case IMAGETYPE_GIF: | ||
96 | + $src_img = imagecreatefromgif($src); | ||
97 | + break; | ||
98 | + | ||
99 | + case IMAGETYPE_JPEG: | ||
100 | + $src_img = imagecreatefromjpeg($src); | ||
101 | + break; | ||
102 | + | ||
103 | + case IMAGETYPE_PNG: | ||
104 | + $src_img = imagecreatefrompng($src); | ||
105 | + break; | ||
106 | + } | ||
107 | + | ||
108 | + if (!$src_img) { | ||
109 | + $this -> msg = "Failed to read the image file"; | ||
110 | + return; | ||
111 | + } | ||
112 | + | ||
113 | + $size = getimagesize($src); | ||
114 | + $size_w = $size[0]; // natural width | ||
115 | + $size_h = $size[1]; // natural height | ||
116 | + | ||
117 | + $src_img_w = $size_w; | ||
118 | + $src_img_h = $size_h; | ||
119 | + | ||
120 | + $degrees = $data -> rotate; | ||
121 | + | ||
122 | + // Rotate the source image | ||
123 | + if (is_numeric($degrees) && $degrees != 0) { | ||
124 | + // PHP's degrees is opposite to CSS's degrees | ||
125 | + $new_img = imagerotate( $src_img, -$degrees, imagecolorallocatealpha($src_img, 0, 0, 0, 127) ); | ||
126 | + | ||
127 | + imagedestroy($src_img); | ||
128 | + $src_img = $new_img; | ||
129 | + | ||
130 | + $deg = abs($degrees) % 180; | ||
131 | + $arc = ($deg > 90 ? (180 - $deg) : $deg) * M_PI / 180; | ||
132 | + | ||
133 | + $src_img_w = $size_w * cos($arc) + $size_h * sin($arc); | ||
134 | + $src_img_h = $size_w * sin($arc) + $size_h * cos($arc); | ||
135 | + | ||
136 | + // Fix rotated image miss 1px issue when degrees < 0 | ||
137 | + $src_img_w -= 1; | ||
138 | + $src_img_h -= 1; | ||
139 | + } | ||
140 | + | ||
141 | + $tmp_img_w = $data -> width; | ||
142 | + $tmp_img_h = $data -> height; | ||
143 | + $dst_img_w = $this ->imgWidth; | ||
144 | + $dst_img_h = $this ->imgHeight; | ||
145 | + | ||
146 | + $src_x = $data -> x; | ||
147 | + $src_y = $data -> y; | ||
148 | + | ||
149 | + if ($src_x <= -$tmp_img_w || $src_x > $src_img_w) { | ||
150 | + $src_x = $src_w = $dst_x = $dst_w = 0; | ||
151 | + } else if ($src_x <= 0) { | ||
152 | + $dst_x = -$src_x; | ||
153 | + $src_x = 0; | ||
154 | + $src_w = $dst_w = min($src_img_w, $tmp_img_w + $src_x); | ||
155 | + } else if ($src_x <= $src_img_w) { | ||
156 | + $dst_x = 0; | ||
157 | + $src_w = $dst_w = min($tmp_img_w, $src_img_w - $src_x); | ||
158 | + } | ||
159 | + | ||
160 | + if ($src_w <= 0 || $src_y <= -$tmp_img_h || $src_y > $src_img_h) { | ||
161 | + $src_y = $src_h = $dst_y = $dst_h = 0; | ||
162 | + } else if ($src_y <= 0) { | ||
163 | + $dst_y = -$src_y; | ||
164 | + $src_y = 0; | ||
165 | + $src_h = $dst_h = min($src_img_h, $tmp_img_h + $src_y); | ||
166 | + } else if ($src_y <= $src_img_h) { | ||
167 | + $dst_y = 0; | ||
168 | + $src_h = $dst_h = min($tmp_img_h, $src_img_h - $src_y); | ||
169 | + } | ||
170 | + | ||
171 | + // Scale to destination position and size | ||
172 | + $ratio = $tmp_img_w / $dst_img_w; | ||
173 | + $dst_x /= $ratio; | ||
174 | + $dst_y /= $ratio; | ||
175 | + $dst_w /= $ratio; | ||
176 | + $dst_h /= $ratio; | ||
177 | + | ||
178 | + $dst_img = imagecreatetruecolor($dst_img_w, $dst_img_h); | ||
179 | + | ||
180 | + // Add transparent background to destination image | ||
181 | + imagefill($dst_img, 0, 0, imagecolorallocatealpha($dst_img, 0, 0, 0, 127)); | ||
182 | + imagesavealpha($dst_img, true); | ||
183 | + | ||
184 | + $result = imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); | ||
185 | + | ||
186 | + if ($result) { | ||
187 | + if (!imagepng($dst_img, $dst)) { | ||
188 | + $this -> msg = "Failed to save the cropped image file"; | ||
189 | + } | ||
190 | + } else { | ||
191 | + $this -> msg = "Failed to crop the image file"; | ||
192 | + } | ||
193 | + | ||
194 | + imagedestroy($src_img); | ||
195 | + imagedestroy($dst_img); | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + private function codeToMessage($code) { | ||
200 | + switch ($code) { | ||
201 | + case UPLOAD_ERR_INI_SIZE: | ||
202 | + $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; | ||
203 | + break; | ||
204 | + | ||
205 | + case UPLOAD_ERR_FORM_SIZE: | ||
206 | + $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; | ||
207 | + break; | ||
208 | + | ||
209 | + case UPLOAD_ERR_PARTIAL: | ||
210 | + $message = 'The uploaded file was only partially uploaded'; | ||
211 | + break; | ||
212 | + | ||
213 | + case UPLOAD_ERR_NO_FILE: | ||
214 | + $message = 'No file was uploaded'; | ||
215 | + break; | ||
216 | + | ||
217 | + case UPLOAD_ERR_NO_TMP_DIR: | ||
218 | + $message = 'Missing a temporary folder'; | ||
219 | + break; | ||
220 | + | ||
221 | + case UPLOAD_ERR_CANT_WRITE: | ||
222 | + $message = 'Failed to write file to disk'; | ||
223 | + break; | ||
224 | + | ||
225 | + case UPLOAD_ERR_EXTENSION: | ||
226 | + $message = 'File upload stopped by extension'; | ||
227 | + break; | ||
228 | + | ||
229 | + default: | ||
230 | + $message = 'Unknown upload error'; | ||
231 | + } | ||
232 | + | ||
233 | + return $message; | ||
234 | + } | ||
235 | + | ||
236 | + public function getResult() { | ||
237 | + return !empty($this -> data) ? $this -> dst : $this -> src; | ||
238 | + } | ||
239 | + | ||
240 | + public function getMsg() { | ||
241 | + return $this -> msg; | ||
242 | + } | ||
243 | + | ||
244 | + public function getSrc() { | ||
245 | + return $this -> src; | ||
246 | + } | ||
247 | +} |
app/Common/Enums/AlipayLoginType.php
0 → 100644
app/Common/Enums/HtTab.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: machengjun | ||
5 | + * Date: 2018/2/10 | ||
6 | + * Time: 下午2:42 | ||
7 | + */ | ||
8 | +namespace App\Common\Enums; | ||
9 | + | ||
10 | + | ||
11 | +class HtTab | ||
12 | +{ | ||
13 | + const GUIDE_PERMISSION = 'G_P'; | ||
14 | + const GUIDE_ORDER = 'G'; | ||
15 | + const RENT_ORDER = 'R'; | ||
16 | + const RENT_REFUND = 'RF'; | ||
17 | + const IMG_HEAD_URL = 'https://dev-1255927177.cos.ap-shanghai.myqcloud.com'; | ||
18 | + const AUDIO_HEAD_URL = 'https://dev-1255927177.cos.ap-shanghai.myqcloud.com'; | ||
19 | + const RENT_SALE_LOCK = 'R_S_L'; | ||
20 | + const DEFAULT_LIMIT = 10; | ||
21 | + const RENT_PRODUCTION_NAME = '晓兔智能讲解器'; | ||
22 | +} |
app/Common/Enums/LoginType.php
0 → 100644
app/Common/Enums/PayMethod.php
0 → 100644
app/Common/Enums/PaySource.php
0 → 100644
app/Common/Enums/SmsType.php
0 → 100644
app/Common/Http.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 10/02/2017 | ||
6 | + * Time: 5:47 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | +class Http | ||
12 | +{ | ||
13 | + public static function Post($curlPost, $url) | ||
14 | + { | ||
15 | + $curl = curl_init(); | ||
16 | + curl_setopt($curl, CURLOPT_URL, $url); | ||
17 | + curl_setopt($curl, CURLOPT_HEADER, false); | ||
18 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
19 | + curl_setopt($curl, CURLOPT_NOBODY, true); | ||
20 | + curl_setopt($curl, CURLOPT_POST, true); | ||
21 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); | ||
22 | + $return_str = curl_exec($curl); | ||
23 | + curl_close($curl); | ||
24 | + return $return_str; | ||
25 | + } | ||
26 | + | ||
27 | + public static function Get($url) | ||
28 | + { | ||
29 | + $curl = curl_init(); | ||
30 | + curl_setopt($curl, CURLOPT_URL, $url); | ||
31 | + curl_setopt($curl, CURLOPT_HEADER, false); | ||
32 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
33 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
34 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | ||
35 | + $return_str = curl_exec($curl); | ||
36 | + curl_close($curl); | ||
37 | + return $return_str; | ||
38 | + } | ||
39 | + | ||
40 | + public static function PostWithHeader($curlPost, $curlHeader, $url) | ||
41 | + { | ||
42 | + $curl = curl_init(); | ||
43 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
44 | + curl_setopt($curl, CURLOPT_URL, $url); | ||
45 | + curl_setopt($curl, CURLOPT_POST, true); | ||
46 | + curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeader); | ||
47 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
48 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); | ||
49 | + $return_str = curl_exec($curl); | ||
50 | + curl_close($curl); | ||
51 | + return $return_str; | ||
52 | + } | ||
53 | + | ||
54 | + public static function GetWithHeader($curlHeader, $url) | ||
55 | + { | ||
56 | + $curl = curl_init(); | ||
57 | + curl_setopt($curl, CURLOPT_URL, $url); | ||
58 | + curl_setopt($curl, CURLOPT_HEADER, $curlHeader); | ||
59 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
60 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
61 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | ||
62 | + $return_str = curl_exec($curl); | ||
63 | + curl_close($curl); | ||
64 | + return $return_str; | ||
65 | + } | ||
66 | + | ||
67 | + public static function WechatPostWithSecurity($curlPost, $url, $useCert=false) | ||
68 | + { | ||
69 | + $curl = curl_init(); | ||
70 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
71 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); | ||
72 | + curl_setopt($curl, CURLOPT_URL, $url); | ||
73 | + curl_setopt($curl, CURLOPT_POST, true); | ||
74 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
75 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); | ||
76 | + | ||
77 | + if($useCert == true){ | ||
78 | + //设置证书 | ||
79 | + //使用证书:cert 与 key 分别属于两个.pem文件 | ||
80 | + curl_setopt($curl,CURLOPT_SSLCERTTYPE,'PEM'); | ||
81 | + curl_setopt($curl,CURLOPT_SSLCERT, config('constants.wechat.ssl_cert_path')); | ||
82 | + curl_setopt($curl,CURLOPT_SSLKEYTYPE,'PEM'); | ||
83 | + curl_setopt($curl,CURLOPT_SSLKEY, config('constants.wechat.ssl_key_path')); | ||
84 | + } | ||
85 | + | ||
86 | + $return_str = curl_exec($curl); | ||
87 | + curl_close($curl); | ||
88 | + return $return_str; | ||
89 | + } | ||
90 | + | ||
91 | + public static function DeleteWithHeader($curlHeader, $url) | ||
92 | + { | ||
93 | + $curl = curl_init(); | ||
94 | + curl_setopt($curl,CURLOPT_HTTPHEADER,$curlHeader); | ||
95 | + curl_setopt($curl,CURLOPT_URL,$url); | ||
96 | + curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'DELETE'); | ||
97 | + | ||
98 | + ob_start(); | ||
99 | + curl_exec($curl); | ||
100 | + $result = ob_get_contents(); | ||
101 | + ob_end_clean(); | ||
102 | + curl_close($curl); | ||
103 | + | ||
104 | + return $result; | ||
105 | + } | ||
106 | +} |
app/Common/Jpush.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 12/02/2017 | ||
6 | + * Time: 10:58 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | +use Exception; | ||
12 | + | ||
13 | +class Jpush | ||
14 | +{ | ||
15 | + public static function pushNotification($userIds, $title, $msg, $params) | ||
16 | + { | ||
17 | + $client = new \JPush(config('constants.jpush.access_key'), config('constants.jpush.secret')); | ||
18 | + | ||
19 | + try | ||
20 | + { | ||
21 | + $res = $client->push() | ||
22 | + ->setPlatform('all') | ||
23 | + ->addAlias($userIds) | ||
24 | + ->addIosNotification($msg, 'iOS sound', "+1", true, 'iOS category', $params) | ||
25 | + ->setMessage($msg, $title, null, $params) | ||
26 | + ->setOptions(null, 864000, null, (bool)config('constants.jpush.production')) | ||
27 | + ->send(); | ||
28 | + } | ||
29 | + catch(Exception $e) | ||
30 | + { | ||
31 | + $res = 'false'; | ||
32 | + } | ||
33 | + | ||
34 | + return $res; | ||
35 | + } | ||
36 | +} |
app/Common/MQ/CheckoutMessageHandler.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 25/04/2017 | ||
6 | + * Time: 8:49 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common\MQ; | ||
10 | + | ||
11 | + | ||
12 | +class CheckoutMessageHandler extends HttpConsumer | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * UnlockMessageHandler constructor. | ||
17 | + */ | ||
18 | + public function __construct() | ||
19 | + { | ||
20 | + parent::__construct(config('constants.mq.url'), | ||
21 | + config('constants.mq.ak'), | ||
22 | + config('constants.mq.sk'), | ||
23 | + config('constants.mq.checkout.consumer'), | ||
24 | + config('constants.mq.checkout.topic')); | ||
25 | + } | ||
26 | + | ||
27 | + protected function handleMessage() | ||
28 | + { | ||
29 | + return true; | ||
30 | + } | ||
31 | +} |
app/Common/MQ/CmdStatusMessageHandler.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 25/04/2017 | ||
6 | + * Time: 8:49 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common\MQ; | ||
10 | + | ||
11 | + | ||
12 | +class CmdStatusMessageHandler extends HttpConsumer | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * UnlockMessageHandler constructor. | ||
17 | + */ | ||
18 | + public function __construct() | ||
19 | + { | ||
20 | + parent::__construct(config('constants.mq.url'), | ||
21 | + config('constants.mq.ak'), | ||
22 | + config('constants.mq.sk'), | ||
23 | + config('constants.mq.cmd_status.consumer'), | ||
24 | + config('constants.mq.cmd_status.topic')); | ||
25 | + } | ||
26 | + | ||
27 | + protected function handleMessage() | ||
28 | + { | ||
29 | + return true; | ||
30 | + } | ||
31 | +} |
app/Common/MQ/HttpConsumer.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 25/04/2017 | ||
6 | + * Time: 8:17 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common\MQ; | ||
10 | + | ||
11 | + | ||
12 | +use App\Common\Http; | ||
13 | + | ||
14 | +class HttpConsumer | ||
15 | +{ | ||
16 | + //签名 | ||
17 | + private static $signature = "Signature"; | ||
18 | + //Consumer ID | ||
19 | + private static $consumerid = "ConsumerID"; | ||
20 | + //访问码 | ||
21 | + private static $aks = "AccessKey"; | ||
22 | + | ||
23 | + /** | ||
24 | + * @var | ||
25 | + */ | ||
26 | + private $url; | ||
27 | + | ||
28 | + /** | ||
29 | + * @var | ||
30 | + */ | ||
31 | + private $ak; | ||
32 | + | ||
33 | + /** | ||
34 | + * @var | ||
35 | + */ | ||
36 | + private $sk; | ||
37 | + | ||
38 | + /** | ||
39 | + * @var | ||
40 | + */ | ||
41 | + private $cid; | ||
42 | + | ||
43 | + /** | ||
44 | + * @var | ||
45 | + */ | ||
46 | + private $topic; | ||
47 | + | ||
48 | + /** | ||
49 | + * HttpConsumer constructor. | ||
50 | + * @param $url | ||
51 | + * @param $ak | ||
52 | + * @param $sk | ||
53 | + * @param $cid | ||
54 | + * @param $topic | ||
55 | + */ | ||
56 | + public function __construct($url, $ak, $sk, $cid, $topic) | ||
57 | + { | ||
58 | + $this->url = $url; | ||
59 | + $this->ak = $ak; | ||
60 | + $this->sk = $sk; | ||
61 | + $this->cid = $cid; | ||
62 | + $this->topic = $topic; | ||
63 | + } | ||
64 | + | ||
65 | + protected function handleMessage() | ||
66 | + { | ||
67 | + return true; | ||
68 | + } | ||
69 | + | ||
70 | + public function consume() | ||
71 | + { | ||
72 | + $newline = "\n"; | ||
73 | + | ||
74 | + while (true) | ||
75 | + { | ||
76 | + try | ||
77 | + { | ||
78 | + //构造时间戳 | ||
79 | + $date = time()*1000; | ||
80 | + //签名字符串 | ||
81 | + $signString = $this->topic.$newline.$this->cid.$newline.$date; | ||
82 | + //计算签名 | ||
83 | + $sign = Util::calSignature($signString,$this->sk); | ||
84 | + //构造签名标记 | ||
85 | + $signFlag = $this::$signature.":".$sign; | ||
86 | + //构造密钥标记 | ||
87 | + $akFlag = $this::$aks.":".$this->ak; | ||
88 | + //标记 | ||
89 | + $consumerFlag = $this::$consumerid.":".$this->cid; | ||
90 | + //构造HTTP请求发送内容类型标记 | ||
91 | + $contentFlag = "Content-Type:text/html;charset=UTF-8"; | ||
92 | + //构造HTTP头部信息 | ||
93 | + $headers = array( | ||
94 | + $signFlag, | ||
95 | + $akFlag, | ||
96 | + $consumerFlag, | ||
97 | + $contentFlag, | ||
98 | + ); | ||
99 | + //构造HTTP请求URL | ||
100 | + $getUrl = $this->url."/message/?topic=".$this->topic."&time=".$date."&num=32"; | ||
101 | + | ||
102 | + $result = Http::GetWithHeader($headers, $getUrl); | ||
103 | + //解析HTTP应答信息 | ||
104 | + $messages = json_decode($result,true); | ||
105 | + //如果应答信息中的没有包含任何的Topic信息,则直接跳过 | ||
106 | + if (count($messages) ==0) | ||
107 | + { | ||
108 | + continue; | ||
109 | + } | ||
110 | + //依次遍历每个Topic消息 | ||
111 | + foreach ((array)$messages as $message) | ||
112 | + { | ||
113 | + var_dump($message); | ||
114 | + | ||
115 | + if ($this->handleMessage()) | ||
116 | + { | ||
117 | + //构造删除Topic消息URL | ||
118 | + $delUrl = $this->url."/message/?msgHandle=".$message['msgHandle']."&topic=".$this->topic."&time=".$date; | ||
119 | + //签名字符串 | ||
120 | + $signString = $this->topic.$newline.$this->cid.$newline.$message['msgHandle'].$newline.$date; | ||
121 | + //计算签名 | ||
122 | + $sign = Util::calSignature($signString,$this->sk); | ||
123 | + //构造签名标记 | ||
124 | + $signFlag = $this::$signature.":".$sign; | ||
125 | + //构造密钥标记 | ||
126 | + $akFlag = $this::$aks.":".$this->ak; | ||
127 | + //构造消费者组标记 | ||
128 | + $consumerFlag = $this::$consumerid.":".$this->cid; | ||
129 | + //构造HTTP请求头部信息 | ||
130 | + $delHeaders = array( | ||
131 | + $signFlag, | ||
132 | + $akFlag, | ||
133 | + $consumerFlag, | ||
134 | + $contentFlag, | ||
135 | + ); | ||
136 | + | ||
137 | + $result = Http::DeleteWithHeader($delHeaders, $delUrl); | ||
138 | + } | ||
139 | + } | ||
140 | + } | ||
141 | + catch (\Exception $e) | ||
142 | + { | ||
143 | + //打印异常信息 | ||
144 | + echo $e->getMessage(); | ||
145 | + } | ||
146 | + } | ||
147 | + } | ||
148 | +} |
app/Common/MQ/HttpProducer.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 25/04/2017 | ||
6 | + * Time: 7:58 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common\MQ; | ||
10 | + | ||
11 | +use App\Common\Http; | ||
12 | + | ||
13 | +/** | ||
14 | + * Class HttpProducer | ||
15 | + * @package App\Common\MQ | ||
16 | + */ | ||
17 | +class HttpProducer | ||
18 | +{ | ||
19 | + //签名 | ||
20 | + private static $signature = "Signature"; | ||
21 | + | ||
22 | + //在MQ控制台创建的Producer ID | ||
23 | + private static $producerId = "ProducerID"; | ||
24 | + | ||
25 | + //阿里云身份验证码 | ||
26 | + private static $aks = "AccessKey"; | ||
27 | + | ||
28 | + /** | ||
29 | + * @var | ||
30 | + */ | ||
31 | + private $url; | ||
32 | + | ||
33 | + /** | ||
34 | + * @var | ||
35 | + */ | ||
36 | + private $ak; | ||
37 | + | ||
38 | + /** | ||
39 | + * @var | ||
40 | + */ | ||
41 | + private $sk; | ||
42 | + | ||
43 | + /** | ||
44 | + * @var | ||
45 | + */ | ||
46 | + private $pid; | ||
47 | + | ||
48 | + /** | ||
49 | + * @var | ||
50 | + */ | ||
51 | + private $topic; | ||
52 | + | ||
53 | + /** | ||
54 | + * @var | ||
55 | + */ | ||
56 | + private $content; | ||
57 | + | ||
58 | + /** | ||
59 | + * @var | ||
60 | + */ | ||
61 | + private $tag; | ||
62 | + | ||
63 | + /** | ||
64 | + * @var | ||
65 | + */ | ||
66 | + private $key; | ||
67 | + | ||
68 | + | ||
69 | + /** | ||
70 | + * HttpProducer constructor. | ||
71 | + * @param $url | ||
72 | + * @param $ak | ||
73 | + * @param $sk | ||
74 | + * @param $pid | ||
75 | + * @param $topic | ||
76 | + * @param $content | ||
77 | + * @param $tag | ||
78 | + * @param $key | ||
79 | + */ | ||
80 | + public function __construct($url, $ak, $sk, $pid, $topic, $content, $tag, $key) | ||
81 | + { | ||
82 | + $this->url = $url; | ||
83 | + $this->ak = $ak; | ||
84 | + $this->sk = $sk; | ||
85 | + $this->pid = $pid; | ||
86 | + $this->topic = $topic; | ||
87 | + $this->content = $content; | ||
88 | + $this->tag = $tag; | ||
89 | + $this->key = $key; | ||
90 | + } | ||
91 | + | ||
92 | + | ||
93 | + /** | ||
94 | + * @param array $headerParam | ||
95 | + * @param array $urlParam | ||
96 | + * @return mixed | ||
97 | + */ | ||
98 | + public function produce($headerParam=array(), $urlParam=array()) | ||
99 | + { | ||
100 | + $date = time()*1000; | ||
101 | + $newline = "\n"; | ||
102 | + //POST请求url | ||
103 | + $postUrl = $this->url."/message/?topic=".$this->topic."&time=".$date."&tag=".$this->tag."&key=".$this->key; | ||
104 | + | ||
105 | + foreach ($urlParam as $key=>$value) | ||
106 | + { | ||
107 | + $postUrl.='&'.$key.'='.$value; | ||
108 | + } | ||
109 | + | ||
110 | + //签名字符串 | ||
111 | + $signString = $this->topic.$newline.$this->pid.$newline.md5($this->content).$newline.$date; | ||
112 | + //计算签名 | ||
113 | + $sign = Util::calSignature($signString,$this->sk); | ||
114 | + | ||
115 | + //构造签名标记 | ||
116 | + $signFlag = $this::$signature.":".$sign; | ||
117 | + //构造密钥标记 | ||
118 | + $akFlag = $this::$aks.":".$this->ak; | ||
119 | + //标记 | ||
120 | + $producerFlag = $this::$producerId.":".$this->pid; | ||
121 | + //构造HTTP请求头部内容类型标记 | ||
122 | + $contentFlag = "Content-Type:text/html;charset=UTF-8"; | ||
123 | + //构造HTTP请求头部 | ||
124 | + $headers = array( | ||
125 | + $signFlag, | ||
126 | + $akFlag, | ||
127 | + $producerFlag, | ||
128 | + $contentFlag, | ||
129 | + ); | ||
130 | + | ||
131 | + foreach ($headerParam as $key=>$value) | ||
132 | + { | ||
133 | + array_push($headers, $key.':'.$value); | ||
134 | + } | ||
135 | + | ||
136 | + $result = Http::PostWithHeader($this->content, $headers, $postUrl); | ||
137 | + | ||
138 | + $result = json_decode($result, true); | ||
139 | + | ||
140 | + return $result; | ||
141 | + } | ||
142 | + | ||
143 | + | ||
144 | + /** | ||
145 | + * @param $delayTime | ||
146 | + * @return mixed | ||
147 | + */ | ||
148 | + public function produceDelayMessage($delayTime) | ||
149 | + { | ||
150 | + $deliveryTime = time()*1000 + $delayTime * 1000; | ||
151 | + $param['startdelivertime'] = $deliveryTime; | ||
152 | + | ||
153 | + return $this->produce(array(), $param); | ||
154 | + } | ||
155 | + | ||
156 | + | ||
157 | + /** | ||
158 | + * @param $shardingKey | ||
159 | + * @return mixed | ||
160 | + */ | ||
161 | + public function produceOrderMessage($shardingKey) | ||
162 | + { | ||
163 | + $param = array(); | ||
164 | + $param['isOrder'] = true; | ||
165 | + $param['shardingKey'] = $shardingKey; | ||
166 | + | ||
167 | + return $this->produce($param); | ||
168 | + } | ||
169 | +} |
app/Common/MQ/UnlockMessageHandler.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 25/04/2017 | ||
6 | + * Time: 8:49 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common\MQ; | ||
10 | + | ||
11 | + | ||
12 | +class UnlockMessageHandler extends HttpConsumer | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * UnlockMessageHandler constructor. | ||
17 | + */ | ||
18 | + public function __construct() | ||
19 | + { | ||
20 | + parent::__construct(config('constants.mq.url'), | ||
21 | + config('constants.mq.ak'), | ||
22 | + config('constants.mq.sk'), | ||
23 | + config('constants.mq.box_unlock.consumer'), | ||
24 | + config('constants.mq.box_unlock.topic')); | ||
25 | + } | ||
26 | + | ||
27 | + protected function handleMessage() | ||
28 | + { | ||
29 | + return true; | ||
30 | + } | ||
31 | +} |
app/Common/MQ/Util.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Common\MQ; | ||
4 | + | ||
5 | +/** | ||
6 | + * Created by PhpStorm. | ||
7 | + * User: billy | ||
8 | + * Date: 25/04/2017 | ||
9 | + * Time: 7:57 PM | ||
10 | + */ | ||
11 | +class Util | ||
12 | +{ | ||
13 | + //计算签名 | ||
14 | + public static function calSignature($str,$key) | ||
15 | + { | ||
16 | + $sign = ""; | ||
17 | + if(function_exists("hash_hmac")) | ||
18 | + { | ||
19 | + $sign = base64_encode(hash_hmac("sha1",$str,$key,true)); | ||
20 | + } | ||
21 | + else | ||
22 | + { | ||
23 | + $blockSize = 64; | ||
24 | + $hashfunc = "sha1"; | ||
25 | + if(strlen($key) > $blockSize) | ||
26 | + { | ||
27 | + $key = pack('H*',$hashfunc($key)); | ||
28 | + } | ||
29 | + $key = str_pad($key,$blockSize,chr(0x00)); | ||
30 | + $ipad = str_repeat(chr(0x36),$blockSize); | ||
31 | + $opad = str_repeat(chr(0x5c),$blockSize); | ||
32 | + $hmac = pack( | ||
33 | + 'H*',$hashfunc( | ||
34 | + ($key^$opad).pack( | ||
35 | + 'H*',$hashfunc($key^$ipad).$str | ||
36 | + ) | ||
37 | + ) | ||
38 | + ); | ||
39 | + $sign = base64_encode($hmac); | ||
40 | + } | ||
41 | + return $sign; | ||
42 | + } | ||
43 | + //计算时间戳 | ||
44 | + public static function microtime_float() | ||
45 | + { | ||
46 | + list($usec,$sec) = explode(" ",microtime()); | ||
47 | + return ((float)$usec+(float)$sec); | ||
48 | + } | ||
49 | +} |
app/Common/Qiniu.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 12/02/2017 | ||
6 | + * Time: 11:03 AM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | +use Qiniu\Auth; | ||
12 | +use Qiniu\Storage\UploadManager; | ||
13 | + | ||
14 | +class Qiniu | ||
15 | +{ | ||
16 | + public static function getUpToken($bucket, $postfix, $policy, $fileName='') | ||
17 | + { | ||
18 | + if ($fileName == '') | ||
19 | + { | ||
20 | + $fileName = Utils::guid().'.'.$postfix; | ||
21 | + } | ||
22 | + else | ||
23 | + { | ||
24 | + $fileName = $fileName.'.'.$postfix; | ||
25 | + } | ||
26 | + | ||
27 | + $policy['saveKey'] = $fileName; | ||
28 | + | ||
29 | + $auth = new Auth(config('constants.qiniu.access_key'), config('constants.qiniu.secret')); | ||
30 | + $token = $auth->uploadToken($bucket, null, 3600, $policy); | ||
31 | + | ||
32 | + return $token; | ||
33 | + } | ||
34 | + | ||
35 | + public static function uploadFile($bucket, $filePath, $postfix="png", $fileName='') | ||
36 | + { | ||
37 | + $token = Qiniu::getUpToken($bucket, $postfix, array(), $fileName); | ||
38 | + $uploadMgr = new UploadManager(); | ||
39 | + $ret = $uploadMgr->putFile($token, null, $filePath); | ||
40 | + | ||
41 | + $result = array(); | ||
42 | + if(!empty($ret[0])) | ||
43 | + { | ||
44 | + $result = $ret[0]['key']; | ||
45 | + } | ||
46 | + else | ||
47 | + { | ||
48 | + $result = ""; | ||
49 | + } | ||
50 | + return $result; | ||
51 | + } | ||
52 | + | ||
53 | + public static function fileUploadWithCorp($avatar_src, $avatar_data, $avatar_file, $width, $height, $bucket, $domain) | ||
54 | + { | ||
55 | + if($width == 0 && $height == 0) | ||
56 | + { | ||
57 | + $data_Array = json_decode($avatar_data, true); | ||
58 | + | ||
59 | + $width = $data_Array['width']; | ||
60 | + $height = $data_Array['height']; | ||
61 | + } | ||
62 | + | ||
63 | + $crop = new CropAvatar($avatar_src, $avatar_data, $avatar_file, $width, $height); | ||
64 | + | ||
65 | + $origin = $crop->getSrc(); | ||
66 | + $result = $crop->getResult(); | ||
67 | + | ||
68 | + $response = Qiniu::uploadFile($bucket, $result); | ||
69 | + | ||
70 | + if(!empty($response)) | ||
71 | + { | ||
72 | + $response = $domain.$response; | ||
73 | + @unlink($origin); | ||
74 | + @unlink($result); | ||
75 | + } | ||
76 | + | ||
77 | + $response = array( | ||
78 | + 'state' => 200, | ||
79 | + 'message' => $crop -> getMsg(), | ||
80 | + 'result' => $response, | ||
81 | + 'filename' => substr($response, strrpos($response, '/') + 1) | ||
82 | + ); | ||
83 | + | ||
84 | + return json_encode($response); | ||
85 | + } | ||
86 | +} |
app/Common/README.md
0 → 100644
1 | +suishengwan common project |
app/Common/RegExpPattern.php
0 → 100644
app/Common/Sms.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 10/02/2017 | ||
6 | + * Time: 6:23 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | +use Illuminate\Support\Facades\Log; | ||
11 | + | ||
12 | +/** | ||
13 | + * Class Sms | ||
14 | + * @package App\Common | ||
15 | + */ | ||
16 | +class Sms | ||
17 | +{ | ||
18 | + /** | ||
19 | + * @return array | ||
20 | + */ | ||
21 | + private static function getHeadArray() | ||
22 | + { | ||
23 | + $AppKey = config('constants.sms.app_key'); | ||
24 | + $AppSecret = config('constants.sms.app_Secret'); | ||
25 | + $Nonce = rand(100000, 999999); | ||
26 | + $CurTime = time(); | ||
27 | + $CheckSum = strtolower(sha1($AppSecret . $Nonce . $CurTime)); | ||
28 | + $head_arr = array(); | ||
29 | + $head_arr[] = 'Content-Type: application/x-www-form-urlencoded'; | ||
30 | + $head_arr[] = 'charset: utf-8'; | ||
31 | + $head_arr[] = 'AppKey:' . $AppKey; | ||
32 | + $head_arr[] = 'Nonce:' . $Nonce; | ||
33 | + $head_arr[] = 'CurTime:' . $CurTime; | ||
34 | + $head_arr[] = 'CheckSum:' . $CheckSum; | ||
35 | + | ||
36 | + return $head_arr; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * @param $mobile | ||
41 | + * @return bool | ||
42 | + */ | ||
43 | + public static function sendCode($mobile) | ||
44 | + { | ||
45 | + $target = config('constants.sms.base_url').config('constants.sms.code_url'); | ||
46 | + | ||
47 | + $head_arr = self::getHeadArray(); | ||
48 | + | ||
49 | + $post_data = "mobile=".$mobile."&codeLen=".config('constants.sms.code_len'); | ||
50 | + | ||
51 | + if (config('constants.sms.template_id')) | ||
52 | + { | ||
53 | + $post_data .= "&templateid=".config('constants.sms.template_id'); | ||
54 | + } | ||
55 | + | ||
56 | + $result = Http::PostWithHeader($post_data, $head_arr, $target); | ||
57 | + | ||
58 | + Log::info('send code result: '.$result); | ||
59 | + | ||
60 | + if (strstr($result,"\"code\":200")) | ||
61 | + return true; | ||
62 | + else | ||
63 | + return false; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * @param $mobile | ||
68 | + * @param $code | ||
69 | + * @return bool | ||
70 | + */ | ||
71 | + public static function verifyCode($mobile, $code) | ||
72 | + { | ||
73 | + $target = config('constants.sms.base_url').config('constants.sms.verify_url'); | ||
74 | + | ||
75 | + $head_arr = self::getHeadArray(); | ||
76 | + | ||
77 | + $post_data = "mobile=".$mobile."&code=".$code; | ||
78 | + | ||
79 | + $result = Http::PostWithHeader($post_data, $head_arr, $target); | ||
80 | + | ||
81 | + if (strstr($result,"\"code\":200")) | ||
82 | + return true; | ||
83 | + else | ||
84 | + return false; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * @param $mobiles | ||
89 | + * @param $template_id | ||
90 | + * @param $params | ||
91 | + * @return bool | ||
92 | + */ | ||
93 | + public static function sendTemplateMessage($mobiles, $template_id, $params) | ||
94 | + { | ||
95 | + $target = config('constants.sms.base_url').config('constants.sms.template_url'); | ||
96 | + | ||
97 | + $head_arr = self::getHeadArray(); | ||
98 | + | ||
99 | + $post_data = "templateid=".$template_id."&mobiles=".json_encode($mobiles)."¶ms=".json_encode($params); | ||
100 | + | ||
101 | + $result = Http::PostWithHeader($post_data, $head_arr, $target); | ||
102 | + | ||
103 | + if (strstr($result,"\"code\":200")) | ||
104 | + return true; | ||
105 | + else | ||
106 | + return false; | ||
107 | + } | ||
108 | +} |
app/Common/TencentMQ/Account.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Common\TencentMQ; | ||
4 | +/* | ||
5 | +Account 对象非线程安全,如果多线程使用,需要每个线程单独初始化Account对象类 | ||
6 | +*/ | ||
7 | +class Account | ||
8 | +{ | ||
9 | + private $secretId; | ||
10 | + private $secretKey; | ||
11 | + private $cmq_client; | ||
12 | + | ||
13 | + /* | ||
14 | + @type host: string | ||
15 | + @param host: 访问的url,例如:https://cmq-queue-gz.api.qcloud.com | ||
16 | + | ||
17 | + @type secretId: string | ||
18 | + @param secretId: 用户的secretId, 腾讯云官网获取 | ||
19 | + | ||
20 | + @type secretKey: string | ||
21 | + @param secretKey: 用户的secretKey,腾讯云官网获取 | ||
22 | + | ||
23 | + @note: Exception | ||
24 | + :: CMQClientParameterException host格式错误 | ||
25 | + */ | ||
26 | + | ||
27 | + public function __construct($host, $secretId, $secretKey) { | ||
28 | + $this->host = $host; | ||
29 | + $this->secretId = $secretId; | ||
30 | + $this->secretKey = $secretKey; | ||
31 | + $this->cmq_client = new CMQClient($host, $secretId, $secretKey); | ||
32 | + } | ||
33 | + | ||
34 | + /* | ||
35 | + * @type sign_method:string | ||
36 | + * @param sign_method : only support sha1 and sha256 | ||
37 | + */ | ||
38 | + public function set_sign_method($sign_method='sha1') | ||
39 | + { | ||
40 | + $this->cmq_client->set_sign_method($sign_method); | ||
41 | + } | ||
42 | + | ||
43 | + | ||
44 | + /* 设置访问的url | ||
45 | + | ||
46 | + @type host: string | ||
47 | + @param host: 访问的url,例如:http://cmq-queue-gz.api.tencentyun.com | ||
48 | + | ||
49 | + @type secretId: string | ||
50 | + @param secretId: 用户的secretId,腾讯云官网获取 | ||
51 | + | ||
52 | + @type secretKey: string | ||
53 | + @param secretKey: 用户的secretKey,腾讯云官网获取 | ||
54 | + | ||
55 | + @note: Exception | ||
56 | + :: CMQClientParameterException host格式错误 | ||
57 | + */ | ||
58 | + public function set_client($host, $secretId=NULL, $secretKey=NULL) { | ||
59 | + if ($secretId == NULL) { | ||
60 | + $secretId = $this->secretId; | ||
61 | + } | ||
62 | + if ($secretKey == NULL) { | ||
63 | + $secretKey = $this->secretKey; | ||
64 | + } | ||
65 | + $this->cmq_client = new CMQClient($host, $secretId, $secretKey); | ||
66 | + } | ||
67 | + | ||
68 | + /* 获取queue client | ||
69 | + | ||
70 | + @rtype: CMQClient object | ||
71 | + @return: 返回使用的CMQClient object | ||
72 | + */ | ||
73 | + public function get_client() { | ||
74 | + return $this->cmq_client; | ||
75 | + } | ||
76 | + | ||
77 | + /* 获取Account的一个Queue对象 | ||
78 | + | ||
79 | + @type queue_name: string | ||
80 | + @param queue_name: 队列名 | ||
81 | + | ||
82 | + @rtype: Queue object | ||
83 | + @return: 返回该Account的一个Queue对象 | ||
84 | + */ | ||
85 | + public function get_queue($queue_name) { | ||
86 | + return new Queue($queue_name, $this->cmq_client); | ||
87 | + } | ||
88 | + | ||
89 | + /* 列出Account的队列 | ||
90 | + | ||
91 | + @type searchWord: string | ||
92 | + @param searchWord: 队列名的前缀 | ||
93 | + | ||
94 | + @type limit: int | ||
95 | + @param limit: list_queue最多返回的队列数 | ||
96 | + | ||
97 | + @type offset: string | ||
98 | + @param offset: list_queue的起始位置,上次list_queue返回的next_offset | ||
99 | + | ||
100 | + @rtype: tuple | ||
101 | + @return: QueueURL的列表和下次list queue的起始位置; 如果所有queue都list出来,next_offset为"". | ||
102 | + */ | ||
103 | + public function list_queue($searchWord = "", $limit = -1, $offset = "") { | ||
104 | + $params = array(); | ||
105 | + if ($searchWord != "") { | ||
106 | + $params['searchWord'] = $searchWord; | ||
107 | + } | ||
108 | + if ($limit != -1) { | ||
109 | + $params['limit'] = $limit; | ||
110 | + } | ||
111 | + if ($offset != "") { | ||
112 | + $params['offset'] = $offset; | ||
113 | + } | ||
114 | + | ||
115 | + $ret_pkg = $this->cmq_client->list_queue($params); | ||
116 | + | ||
117 | + if ($offset == "") { | ||
118 | + $next_offset = count($ret_pkg['queueList']); | ||
119 | + } | ||
120 | + else { | ||
121 | + $next_offset = $offset + count($ret_pkg['queueList']); | ||
122 | + } | ||
123 | + if ($next_offset >= $ret_pkg['totalCount']) { | ||
124 | + $next_offset = ""; | ||
125 | + } | ||
126 | + | ||
127 | + return array("totalCount"=>$ret_pkg['totalCount'], | ||
128 | + "queueList"=>$ret_pkg['queueList'], "next_offset"=>$next_offset); | ||
129 | + } | ||
130 | + | ||
131 | + | ||
132 | + /* 列出Account的主题 | ||
133 | + | ||
134 | + @type searchWord: string | ||
135 | + @param searchWord: 主题关键字 | ||
136 | + | ||
137 | + @type limit: int | ||
138 | + @param limit: 最多返回的主题数目 | ||
139 | + | ||
140 | + @type offset: string | ||
141 | + @param offset: list_topic的起始位置,上次list_topic返回的next_offset | ||
142 | + | ||
143 | + @rtype: tuple | ||
144 | + @return: TopicURL的列表和下次list topic的起始位置; 如果所有topic都list出来,next_offset为"". | ||
145 | + */ | ||
146 | + public function list_topic($searchWord = "", $limit = -1, $offset = ""){ | ||
147 | + $params = array(); | ||
148 | + if($searchWord != ""){ | ||
149 | + $params['searchWord'] = $searchWord; | ||
150 | + } | ||
151 | + if($limit != -1){ | ||
152 | + $params['limit'] = $limit; | ||
153 | + } | ||
154 | + if($offset != ""){ | ||
155 | + $params['offset'] = $offset; | ||
156 | + } | ||
157 | + | ||
158 | + $resp = $this->cmq_client->list_topic($params); | ||
159 | + | ||
160 | + if ($offset == ""){ | ||
161 | + $next_offset = count($resp['topicList']); | ||
162 | + } | ||
163 | + else{ | ||
164 | + $next_offset = $offset + count($resp['topicList']); | ||
165 | + } | ||
166 | + if($next_offset >= $resp['totalCount']){ | ||
167 | + $next_offset = ""; | ||
168 | + } | ||
169 | + | ||
170 | + return array("totalCoult" => $resp['totalCount'], | ||
171 | + "topicList" =>$resp['topicList'], | ||
172 | + "next_offset" => $next_offset); | ||
173 | + } | ||
174 | + | ||
175 | + | ||
176 | + /* 获取Account的一个Topic对象 | ||
177 | + | ||
178 | + @type topic_name: string | ||
179 | + @param queue_name: | ||
180 | + | ||
181 | + @rtype: Topic object | ||
182 | + @return: 返回该Account的一个Topic对象 | ||
183 | + */ | ||
184 | + public function get_topic($topic_name) | ||
185 | + { | ||
186 | + return new Topic($topic_name,$this->cmq_client); | ||
187 | + } | ||
188 | + | ||
189 | + | ||
190 | + /* 获取Account的一个Subscription对象 | ||
191 | + | ||
192 | + @type topic_name: string | ||
193 | + @param queue_name: | ||
194 | + | ||
195 | + @type subscription_name :string | ||
196 | + @param subscription_name: | ||
197 | + | ||
198 | + @rtype: Subscription object | ||
199 | + @return: 返回该Account的一个Subscription对象 | ||
200 | + */ | ||
201 | + public function get_subscription($topic_name, $subscription_name) | ||
202 | + { | ||
203 | + return new Subscription($topic_name, $subscription_name,$this->cmq_client); | ||
204 | + } | ||
205 | + | ||
206 | + | ||
207 | +} |
app/Common/TencentMQ/CMQClient.php
0 → 100644
1 | +<?php | ||
2 | +namespace App\Common\TencentMQ; | ||
3 | + | ||
4 | +class CMQClient | ||
5 | +{ | ||
6 | + private $host; | ||
7 | + private $secretId; | ||
8 | + private $secretKey; | ||
9 | + private $version; | ||
10 | + private $http; | ||
11 | + private $method; | ||
12 | + private $URISEC = '/v2/index.php'; | ||
13 | + | ||
14 | + public function __construct($host, $secretId, $secretKey, $version = "SDK_PHP_1.3", $method = "POST") { | ||
15 | + $this->process_host($host); | ||
16 | + $this->secretId = $secretId; | ||
17 | + $this->secretKey = $secretKey; | ||
18 | + $this->version = $version; | ||
19 | + $this->method = $method; | ||
20 | + $this->sign_method='HmacSHA1'; | ||
21 | + $this->http = new CMQHttp($this->host); | ||
22 | + } | ||
23 | + | ||
24 | + protected function process_host($host) { | ||
25 | + if (strpos($host,"http://") === 0) { | ||
26 | + $_host = substr($host,7,strlen($host)-7); | ||
27 | + } | ||
28 | + elseif (strpos($host,"https://") === 0) { | ||
29 | + $_host = substr($host,8,strlen($host)-8); | ||
30 | + } | ||
31 | + else { | ||
32 | + throw new CMQClientParameterException("Only support http(s) prototol. Invalid endpoint:" . $host); | ||
33 | + } | ||
34 | + if ($_host[strlen($_host)-1]=="/") { | ||
35 | + $this->host = substr($_host,0,strlen($_host)-1); | ||
36 | + } | ||
37 | + else { | ||
38 | + $this->host = $_host; | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + public function set_sign_method($sign_method = 'sha1') | ||
43 | + { | ||
44 | + if ($sign_method == 'sha1' || $sign_method == 'HmacSHA256') | ||
45 | + $this->sign_method = 'HmacSHA1'; | ||
46 | + elseif ($sign_method == 'sha256') | ||
47 | + $this->sign_method = 'HmacSHA256'; | ||
48 | + else | ||
49 | + throw new CMQClientParameterException('Only support sign method HmasSHA256 or HmacSHA1 . Invalid sign method:' . $sign_method); | ||
50 | + | ||
51 | + } | ||
52 | + public function set_method($method='POST') { | ||
53 | + $this->method = $method; | ||
54 | + } | ||
55 | + | ||
56 | + public function set_connection_timeout($connection_timeout) { | ||
57 | + $this->http->set_connection_timeout($connection_timeout); | ||
58 | + } | ||
59 | + | ||
60 | + public function set_keep_alive($keep_alive) { | ||
61 | + $this->http->set_keep_alive($keep_alive); | ||
62 | + } | ||
63 | + | ||
64 | + protected function build_req_inter($action, $params, &$req_inter) { | ||
65 | + $_params = $params; | ||
66 | + $_params['Action'] = ucfirst($action); | ||
67 | + $_params['RequestClient'] = $this->version; | ||
68 | + | ||
69 | + if(!isset($_params['SecretId'])) | ||
70 | + $_params['SecretId'] = $this->secretId; | ||
71 | + | ||
72 | + if (!isset($_params['Nonce'])) | ||
73 | + $_params['Nonce'] = rand(1, 65535); | ||
74 | + | ||
75 | + if (!isset($_params['Timestamp'])) | ||
76 | + $_params['Timestamp'] = time(); | ||
77 | + | ||
78 | + if (!isset($_params['SignatureMethod'])) | ||
79 | + $_params['SignatureMethod'] = $this->sign_method; | ||
80 | + | ||
81 | + $plainText = Signature::makeSignPlainText($_params, | ||
82 | + $this->method, $this->host, $req_inter->uri); | ||
83 | + $_params['Signature'] = Signature::sign($plainText, $this->secretKey,$this->sign_method); | ||
84 | + | ||
85 | + $req_inter->data = http_build_query($_params); | ||
86 | + $this->build_header($req_inter); | ||
87 | + } | ||
88 | + | ||
89 | + protected function build_header(&$req_inter) { | ||
90 | + if ($this->http->is_keep_alive()) { | ||
91 | + $req_inter->header["Connection"] = "Keep-Alive"; | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + protected function check_status($resp_inter) { | ||
96 | + if ($resp_inter->status != 200) { | ||
97 | + throw new CMQServerNetworkException($resp_inter->status, $resp_inter->header, $resp_inter->data); | ||
98 | + } | ||
99 | + | ||
100 | + $resp = json_decode($resp_inter->data, TRUE); | ||
101 | + $code = $resp['code']; | ||
102 | + $message = $resp['message']; | ||
103 | + $requestId = $resp['requestId']; | ||
104 | + | ||
105 | + if ($code != 0) { | ||
106 | + throw new CMQServerException($message=$message, $request_id=$requestId, $code=$code, $data=$resp); | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + protected function request($action, $params) { | ||
111 | + // make request internal | ||
112 | + $req_inter = new RequestInternal($this->method, $this->URISEC); | ||
113 | + $this->build_req_inter($action, $params, $req_inter); | ||
114 | + | ||
115 | + $iTimeout = 0; | ||
116 | + | ||
117 | + if(array_key_exists("UserpollingWaitSeconds", $params)) | ||
118 | + { | ||
119 | + $iTimeout=(int)$params['UserpollingWaitSeconds'] ; | ||
120 | + } | ||
121 | + // send request | ||
122 | + $resp_inter = $this->http->send_request($req_inter, $iTimeout ); | ||
123 | + | ||
124 | + return $resp_inter; | ||
125 | + } | ||
126 | + | ||
127 | +//===============================================queue operation=============================================== | ||
128 | + | ||
129 | + public function create_queue($params) { | ||
130 | + $resp_inter = $this->request('CreateQueue', $params); | ||
131 | + $this->check_status($resp_inter); | ||
132 | + } | ||
133 | + | ||
134 | + public function delete_queue($params) { | ||
135 | + $resp_inter = $this->request('DeleteQueue', $params); | ||
136 | + $this->check_status($resp_inter); | ||
137 | + } | ||
138 | + public function rewindQueue($params){ | ||
139 | + $resp_inter = $this->request('RewindQueue', $params); | ||
140 | + $this->check_status($resp_inter); | ||
141 | + } | ||
142 | + public function list_queue($params) { | ||
143 | + $resp_inter = $this->request('ListQueue', $params); | ||
144 | + $this->check_status($resp_inter); | ||
145 | + | ||
146 | + $ret = json_decode($resp_inter->data, TRUE); | ||
147 | + return $ret; | ||
148 | + } | ||
149 | + | ||
150 | + public function set_queue_attributes($params) { | ||
151 | + $resp_inter = $this->request('SetQueueAttributes', $params); | ||
152 | + $this->check_status($resp_inter); | ||
153 | + } | ||
154 | + | ||
155 | + public function get_queue_attributes($params) { | ||
156 | + $resp_inter = $this->request('GetQueueAttributes', $params); | ||
157 | + $this->check_status($resp_inter); | ||
158 | + | ||
159 | + $ret = json_decode($resp_inter->data, TRUE); | ||
160 | + return $ret; | ||
161 | + } | ||
162 | + | ||
163 | + public function send_message($params) { | ||
164 | + $resp_inter = $this->request('SendMessage', $params); | ||
165 | + $this->check_status($resp_inter); | ||
166 | + | ||
167 | + $ret = json_decode($resp_inter->data, TRUE); | ||
168 | + return $ret['msgId']; | ||
169 | + } | ||
170 | + | ||
171 | + public function batch_send_message($params) { | ||
172 | + $resp_inter = $this->request('BatchSendMessage', $params); | ||
173 | + $this->check_status($resp_inter); | ||
174 | + | ||
175 | + $ret = json_decode($resp_inter->data, TRUE); | ||
176 | + return $ret['msgList']; | ||
177 | + } | ||
178 | + | ||
179 | + public function receive_message($params) { | ||
180 | + $resp_inter = $this->request('ReceiveMessage', $params); | ||
181 | + $this->check_status($resp_inter); | ||
182 | + | ||
183 | + $ret = json_decode($resp_inter->data, TRUE); | ||
184 | + return $ret; | ||
185 | + } | ||
186 | + | ||
187 | + public function batch_receive_message($params) { | ||
188 | + $resp_inter = $this->request('BatchReceiveMessage', $params); | ||
189 | + $this->check_status($resp_inter); | ||
190 | + | ||
191 | + $ret = json_decode($resp_inter->data, TRUE); | ||
192 | + return $ret['msgInfoList']; | ||
193 | + } | ||
194 | + | ||
195 | + public function delete_message($params) { | ||
196 | + $resp_inter = $this->request('DeleteMessage', $params); | ||
197 | + $this->check_status($resp_inter); | ||
198 | + } | ||
199 | + | ||
200 | + public function batch_delete_message($params) { | ||
201 | + $resp_inter = $this->request('BatchDeleteMessage', $params); | ||
202 | + $this->check_status($resp_inter); | ||
203 | + } | ||
204 | + | ||
205 | + //=============================================topic operation================================================ | ||
206 | + | ||
207 | + public function create_topic($params){ | ||
208 | + $resp_inter = $this->request("CreateTopic", $params); | ||
209 | + $this->check_status($resp_inter); | ||
210 | + } | ||
211 | + | ||
212 | + public function delete_topic($params){ | ||
213 | + $resp_inter = $this->request("DeleteTopic", $params); | ||
214 | + $this->check_status($resp_inter); | ||
215 | + } | ||
216 | + public function list_topic($params){ | ||
217 | + $resp_inter = $this->request("ListTopic", $params); | ||
218 | + $this->check_status($resp_inter); | ||
219 | + $ret = json_decode($resp_inter->data, TRUE); | ||
220 | + return $ret; | ||
221 | + } | ||
222 | + public function set_topic_attributes($params){ | ||
223 | + $resp_inter = $this->request("SetTopicAttributes", $params); | ||
224 | + $this->check_status($resp_inter); | ||
225 | + } | ||
226 | + public function get_topic_attributes($params){ | ||
227 | + $resp_inter = $this->request("GetTopicAttributes", $params); | ||
228 | + $this->check_status($resp_inter); | ||
229 | + $ret = json_decode($resp_inter->data, TRUE); | ||
230 | + return $ret; | ||
231 | + } | ||
232 | + | ||
233 | + public function publish_message($params){ | ||
234 | + $resp_inter = $this->request("PublishMessage", $params); | ||
235 | + $this->check_status($resp_inter); | ||
236 | + $ret = json_decode($resp_inter->data, TRUE); | ||
237 | + return $ret ; | ||
238 | + } | ||
239 | + public function batch_publish_message($params){ | ||
240 | + $resp_inter = $this->request("BatchPublishMessage", $params); | ||
241 | + $this->check_status($resp_inter); | ||
242 | + $ret = json_decode($resp_inter->data, TRUE); | ||
243 | + return $ret ; | ||
244 | + } | ||
245 | + | ||
246 | + //============================================subscription operation============================================= | ||
247 | + public function create_subscription($params){ | ||
248 | + $resp_inter = $this->request("Subscribe", $params); | ||
249 | + $this->check_status($resp_inter); | ||
250 | + } | ||
251 | + public function clear_filterTags($params){ | ||
252 | + $resp_inter = $this->request("ClearSubscriptionFilterTags", $params); | ||
253 | + $this->check_status($resp_inter); | ||
254 | + } | ||
255 | + public function delete_subscription($params){ | ||
256 | + $resp_inter = $this->request("Unsubscribe", $params); | ||
257 | + $this->check_status($resp_inter); | ||
258 | + } | ||
259 | + public function get_subscription_attributes($params){ | ||
260 | + $resp_inter = $this->request("GetSubscriptionAttributes", $params); | ||
261 | + $this->check_status($resp_inter); | ||
262 | + $ret = json_decode($resp_inter->data, TRUE); | ||
263 | + return $ret; | ||
264 | + } | ||
265 | + public function set_subscription_attributes($params){ | ||
266 | + $resp_inter = $this->request("SetSubscriptionAttributes", $params); | ||
267 | + $this->check_status($resp_inter); | ||
268 | + } | ||
269 | + public function list_subscription($params){ | ||
270 | + $resp_inter = $this->request("ListSubscriptionByTopic", $params); | ||
271 | + $this->check_status($resp_inter); | ||
272 | + $ret = json_decode($resp_inter->data, TRUE); | ||
273 | + return $ret; | ||
274 | + } | ||
275 | +} |
app/Common/TencentMQ/CMQClientException.php
0 → 100644
1 | +<?php | ||
2 | +namespace App\Common\TencentMQ; | ||
3 | + | ||
4 | +class CMQExceptionBase extends \RuntimeException | ||
5 | +{ | ||
6 | + /* | ||
7 | + @type code: int | ||
8 | + @param code: 错误类型 | ||
9 | + | ||
10 | + @type message: string | ||
11 | + @param message: 错误描述 | ||
12 | + | ||
13 | + @type data: array | ||
14 | + @param data: 错误数据 | ||
15 | + */ | ||
16 | + | ||
17 | + public $code; | ||
18 | + public $message; | ||
19 | + public $data; | ||
20 | + | ||
21 | + public function __construct($message, $code=-1, $data=array()) | ||
22 | + { | ||
23 | + parent::__construct($message, $code, null); | ||
24 | + $this->code = $code; | ||
25 | + $this->message = $message; | ||
26 | + $this->data = $data; | ||
27 | + } | ||
28 | + | ||
29 | + public function __toString() | ||
30 | + { | ||
31 | + return "CMQExceptionBase " . $this->get_info(); | ||
32 | + } | ||
33 | + | ||
34 | + public function get_info() | ||
35 | + { | ||
36 | + $info = array("code" => $this->code, | ||
37 | + "data" => json_encode($this->data), | ||
38 | + "message" => $this->message); | ||
39 | + return json_encode($info); | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +class CMQClientException extends CMQExceptionBase | ||
44 | +{ | ||
45 | + public function __construct($message, $code=-1, $data=array()) | ||
46 | + { | ||
47 | + parent::__construct($message, $code, $data); | ||
48 | + } | ||
49 | + | ||
50 | + public function __toString() | ||
51 | + { | ||
52 | + return "CMQClientException " . $this->get_info(); | ||
53 | + } | ||
54 | +} | ||
55 | + | ||
56 | +class CMQClientNetworkException extends CMQClientException | ||
57 | +{ | ||
58 | + /* 网络异常 | ||
59 | + | ||
60 | + @note: 检查endpoint是否正确、本机网络是否正常等; | ||
61 | + */ | ||
62 | + public function __construct($message, $code=-1, $data=array()) | ||
63 | + { | ||
64 | + parent::__construct($message, $code, $data); | ||
65 | + } | ||
66 | + | ||
67 | + public function __toString() | ||
68 | + { | ||
69 | + return "CMQClientNetworkException " . $this->get_info(); | ||
70 | + } | ||
71 | +} | ||
72 | + | ||
73 | +class CMQClientParameterException extends CMQClientException | ||
74 | +{ | ||
75 | + /* 参数格式错误 | ||
76 | + | ||
77 | + @note: 请根据提示修改对应参数; | ||
78 | + */ | ||
79 | + public function __construct($message, $code=-1, $data=array()) | ||
80 | + { | ||
81 | + parent::__construct($message, $code, $data); | ||
82 | + } | ||
83 | + | ||
84 | + public function __toString() | ||
85 | + { | ||
86 | + return "CMQClientParameterException " . $this->get_info(); | ||
87 | + } | ||
88 | +} | ||
89 | + | ||
90 | +class CMQServerNetworkException extends CMQExceptionBase | ||
91 | +{ | ||
92 | + //服务器网络异常 | ||
93 | + | ||
94 | + public $status; | ||
95 | + public $header; | ||
96 | + public $data; | ||
97 | + | ||
98 | + public function __construct($status = 200, $header = NULL, $data = "") | ||
99 | + { | ||
100 | + if ($header == NULL) { | ||
101 | + $header = array(); | ||
102 | + } | ||
103 | + $this->status = $status; | ||
104 | + $this->header = $header; | ||
105 | + $this->data = $data; | ||
106 | + } | ||
107 | + | ||
108 | + public function __toString() | ||
109 | + { | ||
110 | + $info = array("status" => $this->status, | ||
111 | + "header" => json_encode($this->header), | ||
112 | + "data" => $this->data); | ||
113 | + | ||
114 | + return "CMQServerNetworkException " . json_encode($info); | ||
115 | + } | ||
116 | +} | ||
117 | + | ||
118 | +class CMQServerException extends CMQExceptionBase | ||
119 | +{ | ||
120 | + /* cmq处理异常 | ||
121 | + | ||
122 | + @note: 根据code进行分类处理,常见错误类型: | ||
123 | + : 4000 参数不合法 | ||
124 | + : 4100 鉴权失败:密钥不存在/失效 | ||
125 | + : 4300 账户欠费了 | ||
126 | + : 4400 消息大小超过队列属性设置的最大值 | ||
127 | + : 4410 已达到队列最大的消息堆积数 | ||
128 | + : 4420 qps限流 | ||
129 | + : 4430 删除消息的句柄不合法或者过期了 | ||
130 | + : 4440 队列不存在 | ||
131 | + : 4450 队列个数超过限制 | ||
132 | + : 4460 队列已经存在 | ||
133 | + : 6000 服务器内部错误 | ||
134 | + : 6010 批量删除消息失败(具体原因还要看每个消息删除失败的错误码) | ||
135 | + : 7000 空消息,即队列当前没有可用消息 | ||
136 | + : 更多错误类型请登录腾讯云消息服务官网进行了解; | ||
137 | + */ | ||
138 | + | ||
139 | + public $request_id; | ||
140 | + public function __construct($message, $request_id, $code=-1, $data=array()) | ||
141 | + { | ||
142 | + parent::__construct($message, $code, $data); | ||
143 | + $this->request_id = $request_id; | ||
144 | + } | ||
145 | + | ||
146 | + public function __toString() | ||
147 | + { | ||
148 | + return "CMQServerException " . $this->get_info() . ", RequestID:" . $this->request_id; | ||
149 | + } | ||
150 | +} | ||
151 | + | ||
152 | +?> |
app/Common/TencentMQ/CMQHttp.php
0 → 100644
1 | +<?php | ||
2 | +namespace App\Common\TencentMQ; | ||
3 | + | ||
4 | +class CMQHttp | ||
5 | +{ | ||
6 | + private $connection_timeout; | ||
7 | + private $keep_alive; | ||
8 | + private $host; | ||
9 | + | ||
10 | + public function __construct($host, $connection_timeout=10, $keep_alive=true) { | ||
11 | + $this->connection_timeout = $connection_timeout; | ||
12 | + $this->keep_alive = $keep_alive; | ||
13 | + $this->host = $host . "" . "/v2/index.php"; | ||
14 | + $this->curl = NULL; | ||
15 | + } | ||
16 | + | ||
17 | + public function set_method($method='POST') { | ||
18 | + $this->method = $method; | ||
19 | + } | ||
20 | + | ||
21 | + public function set_connection_timeout($connection_timeout) { | ||
22 | + $this->connection_timeout = $connection_timeout; | ||
23 | + } | ||
24 | + | ||
25 | + public function set_keep_alive($keep_alive) { | ||
26 | + $this->keep_alive = $keep_alive; | ||
27 | + } | ||
28 | + | ||
29 | + public function is_keep_alive() { | ||
30 | + return $this->keep_alive; | ||
31 | + } | ||
32 | + | ||
33 | + public function send_request($req_inter, $userTimeout) { | ||
34 | + if(!$this->keep_alive) | ||
35 | + { | ||
36 | + $this->curl = curl_init(); | ||
37 | + } | ||
38 | + else | ||
39 | + { | ||
40 | + if($this->curl == NULL) | ||
41 | + $this->curl = curl_init(); | ||
42 | + } | ||
43 | + | ||
44 | + if($this->curl == NULL) | ||
45 | + { | ||
46 | + throw new CMQClientException("Curl init failed"); | ||
47 | + return; | ||
48 | + } | ||
49 | + | ||
50 | + $url = $this->host; | ||
51 | + if ($req_inter->method == 'POST') | ||
52 | + { | ||
53 | + curl_setopt($this->curl, CURLOPT_POST, 1); | ||
54 | + curl_setopt($this->curl, CURLOPT_POSTFIELDS, $req_inter->data); | ||
55 | + } | ||
56 | + else | ||
57 | + { | ||
58 | + $url .= $req_inter->uri . '?' . $req_inter->data; | ||
59 | + } | ||
60 | + | ||
61 | + if (isset($req_inter->header)) { | ||
62 | + curl_setopt($this->curl, CURLOPT_HTTPHEADER, $req_inter->header); | ||
63 | + } | ||
64 | + | ||
65 | + curl_setopt($this->curl, CURLOPT_URL, $url); | ||
66 | + curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->connection_timeout +$userTimeout ); | ||
67 | + | ||
68 | + curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); | ||
69 | + | ||
70 | + if (false !== strpos($url, "https")) { | ||
71 | + // 证书 | ||
72 | + // curl_setopt($ch,CURLOPT_CAINFO,"ca.crt"); | ||
73 | + curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); | ||
74 | + curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false); | ||
75 | + } | ||
76 | + $resultStr = curl_exec($this->curl); | ||
77 | + if(curl_errno($this->curl)) { | ||
78 | + throw new CMQClientNetworkException(curl_error($this->curl)); | ||
79 | + } | ||
80 | + $info = curl_getinfo($this->curl); | ||
81 | + $resp_inter = new ResponseInternal($info['http_code'], NULL, $resultStr); | ||
82 | + return $resp_inter; | ||
83 | + } | ||
84 | +} | ||
85 | + | ||
86 | +class RequestInternal | ||
87 | +{ | ||
88 | + public $header; | ||
89 | + public $method; | ||
90 | + public $uri; | ||
91 | + public $data; | ||
92 | + | ||
93 | + public function __construct($method = "", $uri = "", $header = NULL, $data = "") { | ||
94 | + if ($header == NULL) { | ||
95 | + $header = array(); | ||
96 | + } | ||
97 | + $this->method = $method; | ||
98 | + $this->uri = $uri; | ||
99 | + $this->header = $header; | ||
100 | + $this->data = $data; | ||
101 | + } | ||
102 | + | ||
103 | + public function __toString() | ||
104 | + { | ||
105 | + $info = array("method" => $this->method, | ||
106 | + "uri" => $this->uri, | ||
107 | + "header" => json_encode($this->header), | ||
108 | + "data" => $this->data); | ||
109 | + return json_encode($info); | ||
110 | + } | ||
111 | +} | ||
112 | + | ||
113 | +class ResponseInternal | ||
114 | +{ | ||
115 | + public $header; | ||
116 | + public $status; | ||
117 | + public $data; | ||
118 | + | ||
119 | + public function __construct($status = 0, $header = NULL, $data = "") { | ||
120 | + if ($header == NULL) { | ||
121 | + $header = array(); | ||
122 | + } | ||
123 | + $this->status = $status; | ||
124 | + $this->header = $header; | ||
125 | + $this->data = $data; | ||
126 | + } | ||
127 | + | ||
128 | + public function __toString() | ||
129 | + { | ||
130 | + $info = array("status" => $this->status, | ||
131 | + "header" => json_encode($this->header), | ||
132 | + "data" => $this->data); | ||
133 | + return json_encode($info); | ||
134 | + } | ||
135 | +} | ||
136 | + |
app/Common/TencentMQ/HttpProducer.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 10/02/2018 | ||
6 | + * Time: 2:47 PM | ||
7 | + */ | ||
8 | +namespace App\Common\TencentMQ; | ||
9 | + | ||
10 | + | ||
11 | +use Illuminate\Support\Facades\Log; | ||
12 | + | ||
13 | +class HttpProducer | ||
14 | +{ | ||
15 | + private $host; | ||
16 | + private $secretId; | ||
17 | + private $secretKey; | ||
18 | + | ||
19 | + /* | ||
20 | + @type host: string | ||
21 | + @param host: 访问的url,例如:https://cmq-queue-gz.api.qcloud.com | ||
22 | + | ||
23 | + @type secretId: string | ||
24 | + @param secretId: 用户的secretId, 腾讯云官网获取 | ||
25 | + | ||
26 | + @type secretKey: string | ||
27 | + @param secretKey: 用户的secretKey,腾讯云官网获取 | ||
28 | + | ||
29 | + @note: Exception | ||
30 | + :: CMQClientParameterException host格式错误 | ||
31 | + */ | ||
32 | + | ||
33 | + public function __construct($host, $secretId, $secretKey) { | ||
34 | + $this->host = $host; | ||
35 | + $this->secretId = $secretId; | ||
36 | + $this->secretKey = $secretKey; | ||
37 | + $this->cmq_client = new CMQClient($host, $secretId, $secretKey); | ||
38 | + } | ||
39 | + | ||
40 | + | ||
41 | + public function sendMessage($queueName, $messageBody, $delay = 0) { | ||
42 | + | ||
43 | + $account = new Account($this->host, $this->secretId, $this->secretKey); | ||
44 | + | ||
45 | + $queue = $account->get_queue($queueName); | ||
46 | + | ||
47 | + $msg = new Message($messageBody); | ||
48 | + $re_msg = $queue->send_message($msg, $delay); | ||
49 | + | ||
50 | + Log::info('ret_msg is'.json_encode($re_msg)); | ||
51 | + | ||
52 | + return $re_msg; | ||
53 | + } | ||
54 | +} |
app/Common/TencentMQ/Queue.php
0 → 100644
1 | +<?php | ||
2 | +namespace App\Common\TencentMQ; | ||
3 | + | ||
4 | +class Queue | ||
5 | +{ | ||
6 | + private $queue_name; | ||
7 | + private $cmq_client; | ||
8 | + private $encoding; | ||
9 | + | ||
10 | + public function __construct($queue_name, $cmq_client, $encoding=false) { | ||
11 | + $this->queue_name = $queue_name; | ||
12 | + $this->cmq_client = $cmq_client; | ||
13 | + $this->encoding = $encoding; | ||
14 | + } | ||
15 | + | ||
16 | + /* 设置是否对消息体进行base64编码 | ||
17 | + | ||
18 | + @type encoding: bool | ||
19 | + @param encoding: 是否对消息体进行base64编码 | ||
20 | + */ | ||
21 | + public function set_encoding($encoding) { | ||
22 | + $this->encoding = $encoding; | ||
23 | + } | ||
24 | + | ||
25 | + /* 创建队列 | ||
26 | + | ||
27 | + @type queue_meta: QueueMeta object | ||
28 | + @param queue_meta: QueueMeta对象,设置队列的属性 | ||
29 | + */ | ||
30 | + public function create($queue_meta) { | ||
31 | + $params = array( | ||
32 | + 'queueName' => $this->queue_name, | ||
33 | + 'pollingWaitSeconds' => $queue_meta->pollingWaitSeconds, | ||
34 | + 'visibilityTimeout' => $queue_meta->visibilityTimeout, | ||
35 | + 'maxMsgSize' => $queue_meta->maxMsgSize, | ||
36 | + 'msgRetentionSeconds' => $queue_meta->msgRetentionSeconds, | ||
37 | + 'rewindSeconds' => $queue_meta->rewindSeconds, | ||
38 | + ); | ||
39 | + if ($queue_meta->maxMsgHeapNum > 0) { | ||
40 | + $params['maxMsgHeapNum'] = $queue_meta->maxMsgHeapNum; | ||
41 | + } | ||
42 | + $this->cmq_client->create_queue($params); | ||
43 | + } | ||
44 | + | ||
45 | + /* 获取队列属性 | ||
46 | + | ||
47 | + @rtype: QueueMeta object | ||
48 | + @return 队列的属性 | ||
49 | + */ | ||
50 | + public function get_attributes() { | ||
51 | + $params = array( | ||
52 | + 'queueName' => $this->queue_name | ||
53 | + ); | ||
54 | + $resp = $this->cmq_client->get_queue_attributes($params); | ||
55 | + $queue_meta = new QueueMeta(); | ||
56 | + $queue_meta->queueName = $this->queue_name; | ||
57 | + $this->__resp2meta__($queue_meta, $resp); | ||
58 | + return $queue_meta; | ||
59 | + } | ||
60 | + | ||
61 | + /* 设置队列属性 | ||
62 | + | ||
63 | + @type queue_meta: QueueMeta object | ||
64 | + @param queue_meta: QueueMeta对象,设置队列的属性 | ||
65 | + */ | ||
66 | + public function set_attributes($queue_meta) { | ||
67 | + $params = array( | ||
68 | + 'queueName' => $this->queue_name, | ||
69 | + 'pollingWaitSeconds' => $queue_meta->pollingWaitSeconds, | ||
70 | + 'visibilityTimeout' => $queue_meta->visibilityTimeout, | ||
71 | + 'maxMsgSize' => $queue_meta->maxMsgSize, | ||
72 | + 'msgRetentionSeconds' => $queue_meta->msgRetentionSeconds, | ||
73 | + 'rewindSeconds' => $queue_meta->rewindSeconds | ||
74 | + ); | ||
75 | + if ($queue_meta->maxMsgHeapNum > 0) { | ||
76 | + $params['maxMsgHeapNum'] = $queue_meta->maxMsgHeapNum; | ||
77 | + } | ||
78 | + | ||
79 | + $this->cmq_client->set_queue_attributes($params); | ||
80 | + } | ||
81 | + | ||
82 | + | ||
83 | + public function rewindQueue($backTrackingTime){ | ||
84 | + $params = array( | ||
85 | + 'queueName' => $this->queue_name, | ||
86 | + 'startConsumeTime' => $backTrackingTime | ||
87 | + ); | ||
88 | + $this->cmq_client->rewindQueue($params); | ||
89 | + } | ||
90 | + | ||
91 | + /* 删除队列 | ||
92 | + | ||
93 | + */ | ||
94 | + public function delete() { | ||
95 | + $params = array('queueName' => $this->queue_name); | ||
96 | + $this->cmq_client->delete_queue($params); | ||
97 | + } | ||
98 | + | ||
99 | + /* 发送消息 | ||
100 | + | ||
101 | + @type message: Message object | ||
102 | + @param message: 发送的Message object | ||
103 | + | ||
104 | + @rtype: Message object | ||
105 | + @return 消息发送成功的返回属性,包含MessageId | ||
106 | + | ||
107 | + */ | ||
108 | + public function send_message($message, $delayTime = 0) { | ||
109 | + if ($this->encoding) { | ||
110 | + $msgBody = base64_encode($message->msgBody); | ||
111 | + } | ||
112 | + else { | ||
113 | + $msgBody = $message->msgBody; | ||
114 | + } | ||
115 | + $params = array( | ||
116 | + 'queueName' => $this->queue_name, | ||
117 | + 'msgBody' => $msgBody, | ||
118 | + 'delaySeconds' => $delayTime | ||
119 | + ); | ||
120 | + $msgId = $this->cmq_client->send_message($params); | ||
121 | + $retmsg = new Message(); | ||
122 | + $retmsg->msgId = $msgId; | ||
123 | + return $retmsg; | ||
124 | + } | ||
125 | + | ||
126 | + /* 批量发送消息 | ||
127 | + | ||
128 | + @type messages: list of Message object | ||
129 | + @param messages: 发送的Message object list | ||
130 | + | ||
131 | + @rtype: list of Message object | ||
132 | + @return 多条消息发送成功的返回属性,包含MessageId | ||
133 | + */ | ||
134 | + public function batch_send_message($messages,$delayTime = 0) { | ||
135 | + $params = array( | ||
136 | + 'queueName' => $this->queue_name, | ||
137 | + 'delaySeconds' => $delayTime | ||
138 | + ); | ||
139 | + $n = 1; | ||
140 | + foreach ($messages as $message) { | ||
141 | + $key = 'msgBody.' . $n; | ||
142 | + if ($this->encoding) { | ||
143 | + $params[$key] = base64_encode($message->msgBody); | ||
144 | + } | ||
145 | + else { | ||
146 | + $params[$key] = $message->msgBody; | ||
147 | + } | ||
148 | + $n += 1; | ||
149 | + } | ||
150 | + $msgList = $this->cmq_client->batch_send_message($params); | ||
151 | + $retMessageList = array(); | ||
152 | + foreach ($msgList as $msg) { | ||
153 | + $retmsg = new Message(); | ||
154 | + $retmsg->msgId = $msg['msgId']; | ||
155 | + $retMessageList [] = $retmsg; | ||
156 | + } | ||
157 | + return $retMessageList; | ||
158 | + } | ||
159 | + | ||
160 | + /* 消费消息 | ||
161 | + | ||
162 | + @type polling_wait_seconds: int | ||
163 | + @param polling_wait_seconds: 本次请求的长轮询时间,单位:秒 | ||
164 | + | ||
165 | + @rtype: Message object | ||
166 | + @return Message object中包含基本属性、临时句柄 | ||
167 | + */ | ||
168 | + public function receive_message($polling_wait_seconds = NULL) { | ||
169 | + | ||
170 | + $params = array('queueName'=>$this->queue_name); | ||
171 | + if ($polling_wait_seconds != NULL) { | ||
172 | + $params['UserpollingWaitSeconds'] = $polling_wait_seconds; | ||
173 | + $params['pollingWaitSeconds'] = $polling_wait_seconds; | ||
174 | + } | ||
175 | + else | ||
176 | + { | ||
177 | + $params['UserpollingWaitSeconds'] =30; | ||
178 | + } | ||
179 | + $resp = $this->cmq_client->receive_message($params); | ||
180 | + $msg = new Message(); | ||
181 | + if ($this->encoding) { | ||
182 | + $msg->msgBody = base64_decode($resp['msgBody']); | ||
183 | + } | ||
184 | + else { | ||
185 | + $msg->msgBody = $resp['msgBody']; | ||
186 | + } | ||
187 | + $msg->msgId = $resp['msgId']; | ||
188 | + $msg->receiptHandle = $resp['receiptHandle']; | ||
189 | + $msg->enqueueTime = $resp['enqueueTime']; | ||
190 | + $msg->nextVisibleTime = $resp['nextVisibleTime']; | ||
191 | + $msg->dequeueCount = $resp['dequeueCount']; | ||
192 | + $msg->firstDequeueTime = $resp['firstDequeueTime']; | ||
193 | + return $msg; | ||
194 | + } | ||
195 | + | ||
196 | + /* 批量消费消息 | ||
197 | + | ||
198 | + @type num_of_msg: int | ||
199 | + @param num_of_msg: 本次请求最多获取的消息条数 | ||
200 | + | ||
201 | + @type polling_wait_seconds: int | ||
202 | + @param polling_wait_seconds: 本次请求的长轮询时间,单位:秒 | ||
203 | + | ||
204 | + @rtype: list of Message object | ||
205 | + @return 多条消息的属性,包含消息的基本属性、临时句柄 | ||
206 | + */ | ||
207 | + public function batch_receive_message($num_of_msg, $polling_wait_seconds = NULL) { | ||
208 | + $params = array('queueName'=>$this->queue_name, 'numOfMsg'=>$num_of_msg); | ||
209 | + if ($polling_wait_seconds != NULL) { | ||
210 | + $params['UserpollingWaitSeconds'] = $polling_wait_seconds; | ||
211 | + $params['pollingWaitSeconds'] = $polling_wait_seconds; | ||
212 | + } | ||
213 | + else{ | ||
214 | + $params['UserpollingWaitSeconds'] = 30; | ||
215 | + } | ||
216 | + $msgInfoList = $this->cmq_client->batch_receive_message($params); | ||
217 | + $retMessageList = array(); | ||
218 | + foreach ($msgInfoList as $msg) { | ||
219 | + $retmsg = new Message(); | ||
220 | + if ($this->encoding) { | ||
221 | + $retmsg->msgBody = base64_decode($msg['msgBody']); | ||
222 | + } | ||
223 | + else { | ||
224 | + $retmsg->msgBody = $msg['msgBody']; | ||
225 | + } | ||
226 | + $retmsg->msgId = $msg['msgId']; | ||
227 | + $retmsg->receiptHandle = $msg['receiptHandle']; | ||
228 | + $retmsg->enqueueTime = $msg['enqueueTime']; | ||
229 | + $retmsg->nextVisibleTime = $msg['nextVisibleTime']; | ||
230 | + $retmsg->dequeueCount = $msg['dequeueCount']; | ||
231 | + $retmsg->firstDequeueTime = $msg['firstDequeueTime']; | ||
232 | + $retMessageList [] = $retmsg; | ||
233 | + } | ||
234 | + return $retMessageList; | ||
235 | + } | ||
236 | + | ||
237 | + /* 删除消息 | ||
238 | + | ||
239 | + @type receipt_handle: string | ||
240 | + @param receipt_handle: 最近一次操作该消息返回的临时句柄 | ||
241 | + */ | ||
242 | + public function delete_message($receipt_handle) { | ||
243 | + $params = array('queueName'=>$this->queue_name, 'receiptHandle'=>$receipt_handle); | ||
244 | + $this->cmq_client->delete_message($params); | ||
245 | + } | ||
246 | + | ||
247 | + /* 批量删除消息 | ||
248 | + | ||
249 | + @type receipt_handle_list: list | ||
250 | + @param receipt_handle_list: batch_receive_message返回的多条消息的临时句柄 | ||
251 | + */ | ||
252 | + public function batch_delete_message($receipt_handle_list) { | ||
253 | + $params = array('queueName'=>$this->queue_name); | ||
254 | + $n = 1; | ||
255 | + foreach ($receipt_handle_list as $receipt_handle) { | ||
256 | + $key = 'receiptHandle.' . $n; | ||
257 | + $params[$key] = $receipt_handle; | ||
258 | + $n += 1; | ||
259 | + } | ||
260 | + $this->cmq_client->batch_delete_message($params); | ||
261 | + } | ||
262 | + | ||
263 | + | ||
264 | + protected function __resp2meta__($queue_meta, $resp) { | ||
265 | + if (isset($resp['queueName'])) { | ||
266 | + $queue_meta->queueName = $resp['queueName']; | ||
267 | + } | ||
268 | + if (isset($resp['maxMsgHeapNum'])) { | ||
269 | + $queue_meta->maxMsgHeapNum = $resp['maxMsgHeapNum']; | ||
270 | + } | ||
271 | + if (isset($resp['pollingWaitSeconds'])) { | ||
272 | + $queue_meta->pollingWaitSeconds = $resp['pollingWaitSeconds']; | ||
273 | + } | ||
274 | + if (isset($resp['visibilityTimeout'])) { | ||
275 | + $queue_meta->visibilityTimeout = $resp['visibilityTimeout']; | ||
276 | + } | ||
277 | + if (isset($resp['maxMsgSize'])) { | ||
278 | + $queue_meta->maxMsgSize = $resp['maxMsgSize']; | ||
279 | + } | ||
280 | + if (isset($resp['msgRetentionSeconds'])) { | ||
281 | + $queue_meta->msgRetentionSeconds = $resp['msgRetentionSeconds']; | ||
282 | + } | ||
283 | + if (isset($resp['createTime'])) { | ||
284 | + $queue_meta->createTime = $resp['createTime']; | ||
285 | + } | ||
286 | + if (isset($resp['lastModifyTime'])) { | ||
287 | + $queue_meta->lastModifyTime = $resp['lastModifyTime']; | ||
288 | + } | ||
289 | + if (isset($resp['activeMsgNum'])) { | ||
290 | + $queue_meta->activeMsgNum = $resp['activeMsgNum']; | ||
291 | + } | ||
292 | + if (isset($resp['rewindSeconds'])) { | ||
293 | + $queue_meta->rewindSeconds = $resp['rewindSeconds']; | ||
294 | + } | ||
295 | + if (isset($resp['inactiveMsgNum'])) { | ||
296 | + $queue_meta->inactiveMsgNum = $resp['inactiveMsgNum']; | ||
297 | + } | ||
298 | + if (isset($resp['rewindmsgNum'])) { | ||
299 | + $queue_meta->rewindmsgNum = $resp['rewindmsgNum']; | ||
300 | + } | ||
301 | + if (isset($resp['minMsgTime'])) { | ||
302 | + $queue_meta->minMsgTime = $resp['minMsgTime']; | ||
303 | + } | ||
304 | + if (isset($resp['delayMsgNum'])) { | ||
305 | + $queue_meta->delayMsgNum = $resp['delayMsgNum']; | ||
306 | + } | ||
307 | + | ||
308 | + } | ||
309 | +} | ||
310 | + | ||
311 | + | ||
312 | +class QueueMeta | ||
313 | +{ | ||
314 | + public $queueName; | ||
315 | + public $maxMsgHeapNum; | ||
316 | + public $pollingWaitSeconds; | ||
317 | + public $visibilityTimeout; | ||
318 | + public $maxMsgSize; | ||
319 | + public $msgRetentionSeconds; | ||
320 | + public $createTime; | ||
321 | + public $lastModifyTime; | ||
322 | + public $activeMsgNum; | ||
323 | + public $inactiveMsgNum; | ||
324 | + public $rewindSeconds; | ||
325 | + public $rewindmsgNum; | ||
326 | + public $minMsgTime; | ||
327 | + public $delayMsgNum; | ||
328 | + /* 队列属性 | ||
329 | + @note: 设置属性 | ||
330 | + :: maxMsgHeapNum: 最大堆积消息数 | ||
331 | + :: pollingWaitSeconds: receive message时,长轮询时间,单位:秒 | ||
332 | + :: visibilityTimeout: 消息可见性超时, 单位:秒 | ||
333 | + :: maxMsgSize: 消息最大长度, 单位:Byte | ||
334 | + :: msgRetentionSeconds: 消息保留周期,单位:秒 | ||
335 | + :: rewindSeconds : 最大回溯时间, 单位:秒 | ||
336 | + | ||
337 | + @note: 非设置属性 | ||
338 | + :: activeMsgNum: 可消费消息数,近似值 | ||
339 | + :: inactiveMsgNum: 正在被消费的消息数,近似值 | ||
340 | + :: createTime: queue创建时间,单位:秒 | ||
341 | + :: lastModifyTime: 修改queue属性的最近时间,单位:秒 | ||
342 | + :: queue_name: 队列名称 | ||
343 | + :: rewindmsgNum:已删除,但是任然在回溯保留时间内的消息数量 | ||
344 | + :: minMsgTime: 消息最小未消费时间,单位为秒 | ||
345 | + :: delayMsgNum:延时消息数量 | ||
346 | + */ | ||
347 | + public function __construct() { | ||
348 | + $this->queueName = ""; | ||
349 | + $this->maxMsgHeapNum = -1; | ||
350 | + $this->pollingWaitSeconds = 0; | ||
351 | + $this->visibilityTimeout = 30; | ||
352 | + $this->maxMsgSize = 65536; | ||
353 | + $this->msgRetentionSeconds = 345600; | ||
354 | + $this->createTime = -1; | ||
355 | + $this->lastModifyTime = -1; | ||
356 | + $this->activeMsgNum = -1; | ||
357 | + $this->inactiveMsgNum = -1; | ||
358 | + $this->rewindSeconds = 0 ; | ||
359 | + $this->rewindmsgNum = 0; | ||
360 | + $this->minMsgTime = 0; | ||
361 | + $this->delayMsgNum = 0 ; | ||
362 | + } | ||
363 | + | ||
364 | + public function __toString() | ||
365 | + { | ||
366 | + $info = array("visibilityTimeout" => $this->visibilityTimeout, | ||
367 | + "maxMsgHeapNum" => $this->maxMsgHeapNum, | ||
368 | + "maxMsgSize" => $this->maxMsgSize, | ||
369 | + "msgRetentionSeconds" => $this->msgRetentionSeconds, | ||
370 | + "pollingWaitSeconds" => $this->pollingWaitSeconds, | ||
371 | + "activeMsgNum" => $this->activeMsgNum, | ||
372 | + "inactiveMsgNum" => $this->inactiveMsgNum, | ||
373 | + "createTime" => date("Y-m-d H:i:s", $this->createTime), | ||
374 | + "lastModifyTime" => date("Y-m-d H:i:s", $this->lastModifyTime), | ||
375 | + "QueueName" => $this->queueName, | ||
376 | + "rewindSeconds" => $this->rewindSeconds, | ||
377 | + "rewindmsgNum" => $this->rewindmsgNum, | ||
378 | + "minMsgTime" => $this->minMsgTime, | ||
379 | + "delayMsgNum" => $this->delayMsgNum); | ||
380 | + return json_encode($info); | ||
381 | + } | ||
382 | +} | ||
383 | + | ||
384 | +class Message | ||
385 | +{ | ||
386 | + public $msgBody; | ||
387 | + public $msgId; | ||
388 | + public $enqueueTime; | ||
389 | + public $receiptHandle; | ||
390 | + | ||
391 | + /* 消息属性 | ||
392 | + | ||
393 | + @note: send_message 指定属性 | ||
394 | + :: msgBody 消息体 | ||
395 | + | ||
396 | + @note: send_message 返回属性 | ||
397 | + :: msgId 消息编号 | ||
398 | + | ||
399 | + @note: receive_message 返回属性,除基本属性外 | ||
400 | + :: receiptHandle 下次删除或修改消息的临时句柄 | ||
401 | + :: enqueueTime 消息入队时间 | ||
402 | + :: nextVisibleTime 下次可被再次消费的时间 | ||
403 | + :: dequeueCount 总共被消费的次数 | ||
404 | + :: firstDequeueTime 第一次被消费的时间 | ||
405 | + */ | ||
406 | + public function __construct($message_body = "") { | ||
407 | + $this->msgBody = $message_body; | ||
408 | + $this->msgId = ""; | ||
409 | + $this->enqueueTime = -1; | ||
410 | + $this->receiptHandle = ""; | ||
411 | + $this->nextVisibleTime = -1; | ||
412 | + $this->dequeueCount = -1; | ||
413 | + $this->firstDequeueTime = -1; | ||
414 | + } | ||
415 | + | ||
416 | + public function __toString() | ||
417 | + { | ||
418 | + $info = array("msgBody" => $this->msgBody, | ||
419 | + "msgId" => $this->msgId, | ||
420 | + "enqueueTime" => date("Y-m-d H:i:s", $this->enqueueTime), | ||
421 | + "nextVisibleTime" => date("Y-m-d H:i:s", $this->nextVisibleTime), | ||
422 | + "firstDequeueTime" => date("Y-m-d H:i:s", $this->firstDequeueTime), | ||
423 | + "dequeueCount" => $this->dequeueCount, | ||
424 | + "receiptHandle" => $this->receiptHandle); | ||
425 | + return json_encode($info); | ||
426 | + } | ||
427 | +} | ||
428 | + |
app/Common/TencentMQ/Signature.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Common\TencentMQ; | ||
4 | + | ||
5 | +/** | ||
6 | + * Sign | ||
7 | + * 签名类 | ||
8 | +*/ | ||
9 | +class Signature | ||
10 | +{ | ||
11 | + /** | ||
12 | + * sign | ||
13 | + * 生成签名 | ||
14 | + * @param string $srcStr 拼接签名源文字符串 | ||
15 | + * @param string $secretKey secretKey | ||
16 | + * @param string $method 请求方法 | ||
17 | + * @return | ||
18 | + */ | ||
19 | + public static function sign($srcStr, $secretKey, $method = 'HmacSHA1') | ||
20 | + { | ||
21 | + switch ($method) { | ||
22 | + case 'HmacSHA1': | ||
23 | + $retStr = base64_encode(hash_hmac('sha1', $srcStr, $secretKey, true)); | ||
24 | + break; | ||
25 | + case 'HmacSHA256': | ||
26 | + $retStr = base64_encode(hash_hmac('sha256', $srcStr, $secretKey, true)); | ||
27 | + break; | ||
28 | + default: | ||
29 | + throw new Exception($method . ' is not a supported encrypt method'); | ||
30 | + return false; | ||
31 | + break; | ||
32 | + } | ||
33 | + | ||
34 | + return $retStr; | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + /** | ||
40 | + * makeSignPlainText | ||
41 | + * 生成拼接签名源文字符串 | ||
42 | + * @param array $requestParams 请求参数 | ||
43 | + * @param string $requestMethod 请求方法 | ||
44 | + * @param string $requestHost 接口域名 | ||
45 | + * @param string $requestPath url路径 | ||
46 | + * @return | ||
47 | + */ | ||
48 | + public static function makeSignPlainText($requestParams, | ||
49 | + $requestMethod = 'POST', $requestHost = YUNAPI_URL, | ||
50 | + $requestPath = '/v2/index.php') | ||
51 | + { | ||
52 | + | ||
53 | + $url = $requestHost . $requestPath; | ||
54 | + | ||
55 | + // 取出所有的参数 | ||
56 | + $paramStr = self::_buildParamStr($requestParams, $requestMethod); | ||
57 | + | ||
58 | + $plainText = $requestMethod . $url . $paramStr; | ||
59 | + | ||
60 | + return $plainText; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * _buildParamStr | ||
65 | + * 拼接参数 | ||
66 | + * @param array $requestParams 请求参数 | ||
67 | + * @param string $requestMethod 请求方法 | ||
68 | + * @return | ||
69 | + */ | ||
70 | + protected static function _buildParamStr($requestParams, $requestMethod = 'POST') | ||
71 | + { | ||
72 | + $paramStr = ''; | ||
73 | + ksort($requestParams); | ||
74 | + $i = 0; | ||
75 | + foreach ($requestParams as $key => $value) | ||
76 | + { | ||
77 | + if ($key == 'Signature') | ||
78 | + { | ||
79 | + continue; | ||
80 | + } | ||
81 | + // 排除上传文件的参数 | ||
82 | + if ($requestMethod == 'POST' && substr($value, 0, 1) == '@') { | ||
83 | + continue; | ||
84 | + } | ||
85 | + // 把 参数中的 _ 替换成 . | ||
86 | + if (strpos($key, '_')) | ||
87 | + { | ||
88 | + $key = str_replace('_', '.', $key); | ||
89 | + } | ||
90 | + | ||
91 | + if ($i == 0) | ||
92 | + { | ||
93 | + $paramStr .= '?'; | ||
94 | + } | ||
95 | + else | ||
96 | + { | ||
97 | + $paramStr .= '&'; | ||
98 | + } | ||
99 | + $paramStr .= $key . '=' . $value; | ||
100 | + ++$i; | ||
101 | + } | ||
102 | + | ||
103 | + return $paramStr; | ||
104 | + } | ||
105 | + | ||
106 | +} | ||
107 | + |
app/Common/TencentMQ/Subscription.php
0 → 100644
1 | +<?php | ||
2 | +namespace App\Common\TencentMQ; | ||
3 | + | ||
4 | +class Subscription | ||
5 | +{ | ||
6 | + private $topic_name; | ||
7 | + private $subscription_name; | ||
8 | + private $cmq_client; | ||
9 | + private $encoding; | ||
10 | + | ||
11 | + public function __construct($topic_name,$subscription_name,$cmq_client,$encoding = false){ | ||
12 | + $this->topic_name = $topic_name; | ||
13 | + $this->subscription_name = $subscription_name; | ||
14 | + $this->cmq_client = $cmq_client; | ||
15 | + $this->encoding = $encoding; | ||
16 | + } | ||
17 | + public function set_encoding($encoding){ | ||
18 | + $this->encoding = $encoding; | ||
19 | + } | ||
20 | + | ||
21 | + /* | ||
22 | + * create subscription | ||
23 | + * @type subscription_meta :SubscriptionMeta | ||
24 | + */ | ||
25 | + public function create($subscription_meta){ | ||
26 | + $params=array( | ||
27 | + 'topicName' => $this->topic_name, | ||
28 | + 'subscriptionName' => $this->subscription_name, | ||
29 | + 'notifyStrategy' => $subscription_meta->NotifyStrategy, | ||
30 | + 'notifyContentFormat' => $subscription_meta->NotifyContentFormat, | ||
31 | + ); | ||
32 | + if ($subscription_meta->Endpoint != ""){ | ||
33 | + $params['endpoint'] = $subscription_meta->Endpoint; | ||
34 | + } | ||
35 | + if($subscription_meta->Protocol !=""){ | ||
36 | + $params['protocol'] = $subscription_meta->Protocol; | ||
37 | + } | ||
38 | + | ||
39 | + if(! $subscription_meta->bindindKey != null && is_array($subscription_meta->bindindKey) && !empty($subscription_meta->bindindKey)){ | ||
40 | + $n = 1; | ||
41 | + foreach ($subscription_meta->bindindKey as $tag) | ||
42 | + { | ||
43 | + $key = 'bindindKey.' . $n; | ||
44 | + $params[$key] = $tag; | ||
45 | + $n += 1 ; | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | + if(! $subscription_meta->FilterTag != null && is_array($subscription_meta->FilterTag) && !empty($subscription_meta->FilterTag)){ | ||
50 | + $n = 1; | ||
51 | + foreach ($subscription_meta->FilterTag as $tag) | ||
52 | + { | ||
53 | + $key = 'filterTag.' . $n; | ||
54 | + $params[$key] = $tag; | ||
55 | + $n += 1 ; | ||
56 | + } | ||
57 | + } | ||
58 | + $this->cmq_client->create_subscription($params); | ||
59 | + } | ||
60 | + | ||
61 | + /* | ||
62 | + * delete subscription | ||
63 | + */ | ||
64 | + public function delete(){ | ||
65 | + | ||
66 | + $params=array( | ||
67 | + 'topicName' => $this->topic_name, | ||
68 | + 'subscriptionName' => $this->subscription_name | ||
69 | + ); | ||
70 | + | ||
71 | + $this->cmq_client->delete_subscription($params); | ||
72 | + } | ||
73 | + /* | ||
74 | + * clear subscription tags | ||
75 | + */ | ||
76 | + public function clearFilterTags(){ | ||
77 | + | ||
78 | + $params=array( | ||
79 | + 'topicName' => $this->topic_name, | ||
80 | + 'subscriptionName' => $this->subscription_name | ||
81 | + ); | ||
82 | + | ||
83 | + $this->cmq_client->clear_filterTags($params); | ||
84 | + } | ||
85 | + | ||
86 | + | ||
87 | + /* | ||
88 | + * get attributes | ||
89 | + * | ||
90 | + * @return subscription_meta :SubscriptionMeta | ||
91 | + */ | ||
92 | + public function get_attributes(){ | ||
93 | + $params=array( | ||
94 | + 'topicName' => $this->topic_name, | ||
95 | + 'subscriptionName' => $this->subscription_name | ||
96 | + ); | ||
97 | + | ||
98 | + $resp = $this->cmq_client->get_subscription_attributes($params); | ||
99 | + | ||
100 | + $subscription_meta = new SubscriptionMeta(); | ||
101 | + $this->__resp2meta($subscription_meta, $resp); | ||
102 | + return $subscription_meta; | ||
103 | + } | ||
104 | + /* | ||
105 | + * set attributes | ||
106 | + * @type subscription_meta : SubscriptionMeta | ||
107 | + * | ||
108 | + */ | ||
109 | + public function set_attributes($subscription_meta){ | ||
110 | + $params = array( | ||
111 | + 'topicName' => $this->topic_name, | ||
112 | + 'subscriptionName' => $this->subscription_name | ||
113 | + ); | ||
114 | + if ($subscription_meta->NotifyStrategy !=""){ | ||
115 | + $params['notifyStrategy'] = $subscription_meta->NotifyStrategy; | ||
116 | + } | ||
117 | + | ||
118 | + if ($subscription_meta->NotifyContentFormat != ""){ | ||
119 | + $params['notifyContentFormat']=$subscription_meta->NotifyContentFormat; | ||
120 | + } | ||
121 | + | ||
122 | + | ||
123 | + if ($subscription_meta->Endpoint != ""){ | ||
124 | + $params['endpoint'] = $subscription_meta->Endpoint; | ||
125 | + } | ||
126 | + if($subscription_meta->Protocol !=""){ | ||
127 | + $params['protocol'] = $subscription_meta->Protocol; | ||
128 | + } | ||
129 | + | ||
130 | + if(! $subscription_meta->bindindKey != null && is_array($subscription_meta->bindindKey) && !empty($subscription_meta->bindindKey)){ | ||
131 | + $n = 1; | ||
132 | + foreach ($subscription_meta->bindindKey as $tag) | ||
133 | + { | ||
134 | + $key = 'bindindKey.' . $n; | ||
135 | + $params[$key] = $tag; | ||
136 | + $n += 1 ; | ||
137 | + } | ||
138 | + } | ||
139 | + | ||
140 | + if(! $subscription_meta->FilterTag != null && is_array($subscription_meta->FilterTag) && !empty($subscription_meta->FilterTag)){ | ||
141 | + $n = 1; | ||
142 | + foreach ($subscription_meta->FilterTag as $tag) | ||
143 | + { | ||
144 | + $key = 'filterTag.' . $n; | ||
145 | + $params[$key] = $tag; | ||
146 | + $n += 1 ; | ||
147 | + } | ||
148 | + } | ||
149 | + | ||
150 | + $this->cmq_client->set_subscription_attributes($params); | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + protected function __resp2meta($subscription_meta, $resp){ | ||
155 | + if (isset($resp['endpoint'])) { | ||
156 | + $subscription_meta->Endpoint = $resp['endpoint']; | ||
157 | + } | ||
158 | + if (isset($resp['protocol'])) { | ||
159 | + $subscription_meta->Protocol = $resp['protocol']; | ||
160 | + } | ||
161 | + if (isset($resp['notifyStrategy'])) { | ||
162 | + $subscription_meta->NotifyStrategy = $resp['notifyStrategy']; | ||
163 | + } | ||
164 | + if (isset($resp['notifyContentFormat'])) { | ||
165 | + $subscription_meta->NotifyContentFormat = $resp['notifyContentFormat']; | ||
166 | + } | ||
167 | + | ||
168 | + if( isset($resp['bindindKey'])){ | ||
169 | + foreach ($resp['bindindKey'] as $tag){ | ||
170 | + array_push($subscription_meta->bindindKey, $tag); | ||
171 | + } | ||
172 | + } | ||
173 | + | ||
174 | + if( isset($resp['filterTags'])){ | ||
175 | + foreach ($resp['filterTags'] as $tag){ | ||
176 | + array_push($subscription_meta->FilterTag, $tag); | ||
177 | + } | ||
178 | + } | ||
179 | + | ||
180 | + } | ||
181 | +} | ||
182 | + | ||
183 | +class SubscriptionMeta | ||
184 | +{ | ||
185 | + // default NotifyStrategy BACKOFF_RETRY | ||
186 | + // default NotifyContentFormat JSON | ||
187 | + | ||
188 | + /* 订阅属性 | ||
189 | + @note: 可修改 | ||
190 | + :: Endpoint 推送消息地址 | ||
191 | + :: Protocal 协议 | ||
192 | + :: FilterTag 订阅 标签 | ||
193 | + :: NotifyStrategy 重试策略 | ||
194 | + :: NotifyContentFormat 推送消息格式 | ||
195 | + */ | ||
196 | + public $Endpoint; | ||
197 | + public $Protocol; | ||
198 | + public $FilterTag; | ||
199 | + public $NotifyStrategy; | ||
200 | + public $NotifyContentFormat; | ||
201 | + | ||
202 | + | ||
203 | + public function __construct(){ | ||
204 | + $this->Endpoint = ""; | ||
205 | + $this->Protocol= ""; | ||
206 | + $this->FilterTag = array(); | ||
207 | + $this->NotifyStrategy = "BACKOFF_RETRY"; | ||
208 | + $this->NotifyContentFormat = "JSON"; | ||
209 | + $this->bindindKey = array(); | ||
210 | + } | ||
211 | + | ||
212 | + public function __toString(){ | ||
213 | + $info = array( | ||
214 | + "endpoint" => $this->Endpoint, | ||
215 | + "protocol" => $this->Protocol, | ||
216 | + "filterTag" => $this->FilterTag, | ||
217 | + "notifyStrategy" => $this->NotifyStrategy, | ||
218 | + "notifyContentFormat" => $this->NotifyContentFormat, | ||
219 | + "bindingKey" => $this->bindindKey, | ||
220 | + ); | ||
221 | + return json_encode($info); | ||
222 | + } | ||
223 | +} |
app/Common/TencentMQ/Topic.php
0 → 100644
1 | +<?php | ||
2 | +namespace App\Common\TencentMQ; | ||
3 | + | ||
4 | +class Topic | ||
5 | +{ | ||
6 | + private $topic_name; | ||
7 | + private $cmq_client; | ||
8 | + private $encoding; | ||
9 | + | ||
10 | + public function __construct($topic_name, $cmq_client, $encoding=false){ | ||
11 | + $this->topic_name = $topic_name; | ||
12 | + $this->cmq_client = $cmq_client; | ||
13 | + $this->encoding = $encoding ; | ||
14 | + } | ||
15 | + | ||
16 | + public function set_encoding($encoding){ | ||
17 | + $this->encoding = $encoding; | ||
18 | + } | ||
19 | + | ||
20 | + | ||
21 | + /* | ||
22 | + * create topic | ||
23 | + * @type topic_meta : TopicMeta | ||
24 | + * @param topic_meta : | ||
25 | + */ | ||
26 | + public function create($topic_meta){ | ||
27 | + $params = array( | ||
28 | + 'topicName' => $this->topic_name, | ||
29 | + 'filterType'=>$topic_meta->filterType | ||
30 | + ); | ||
31 | + | ||
32 | + if ( $topic_meta->maxMsgSize >0 ){ | ||
33 | + $params['maxMsgSize'] = $topic_meta->maxMsgSize; | ||
34 | + } | ||
35 | + $this->cmq_client->create_topic($params); | ||
36 | + } | ||
37 | + /* | ||
38 | + * get attributes | ||
39 | + * | ||
40 | + * @return topic_meta :TopicMeta | ||
41 | + * | ||
42 | + */ | ||
43 | + public function get_attributes(){ | ||
44 | + $params = array( | ||
45 | + 'topicName' => $this->topic_name, | ||
46 | + ); | ||
47 | + $resp = $this->cmq_client->get_topic_attributes($params); | ||
48 | + | ||
49 | + $topic_meta = new TopicMeta(); | ||
50 | + $this->__resp2meta($topic_meta, $resp); | ||
51 | + | ||
52 | + return $topic_meta; | ||
53 | + } | ||
54 | + | ||
55 | + | ||
56 | + /* | ||
57 | + * set attributes | ||
58 | + * | ||
59 | + * @type topic_meta :TopicMeta | ||
60 | + * @param topic_meta : | ||
61 | + */ | ||
62 | + public function set_attributes($topic_meta){ | ||
63 | + | ||
64 | + $params = array( | ||
65 | + 'topicName' => $this->topic_name, | ||
66 | + 'maxMsgSize' => strval($topic_meta->maxMsgSize) | ||
67 | + ); | ||
68 | + $this->cmq_client->set_topic_attributes($params); | ||
69 | + } | ||
70 | + | ||
71 | + | ||
72 | + /* | ||
73 | + * delete topic | ||
74 | + */ | ||
75 | + public function delete(){ | ||
76 | + $params = array( | ||
77 | + 'topicName' => $this->topic_name | ||
78 | + ); | ||
79 | + $this->cmq_client->delete_topic($params); | ||
80 | + } | ||
81 | + | ||
82 | + /* | ||
83 | + * 推送消息 非批量 | ||
84 | + * @type message :string | ||
85 | + * @param message | ||
86 | + * | ||
87 | + * @type vTagList :list | ||
88 | + * @param vTagList 标签 | ||
89 | + * | ||
90 | + * @return message handle | ||
91 | + */ | ||
92 | + | ||
93 | + public function publish_message($message ,$vTagList= null , $routingKey = null){ | ||
94 | + $params=array( | ||
95 | + 'topicName' => $this->topic_name, | ||
96 | + 'msgBody' => $message, | ||
97 | + ); | ||
98 | + if( $routingKey != null){ | ||
99 | + $params['routingKey'] = $routingKey; | ||
100 | + } | ||
101 | + if ($vTagList != null && is_array($vTagList) && !empty($vTagList)) | ||
102 | + { | ||
103 | + $n = 1 ; | ||
104 | + foreach ($vTagList as $tag){ | ||
105 | + $key = 'msgTag.' . $n; | ||
106 | + $params[$key]=$tag; | ||
107 | + $n += 1 ; | ||
108 | + } | ||
109 | + } | ||
110 | + $msgId = $this->cmq_client->publish_message($params); | ||
111 | + | ||
112 | + return $msgId; | ||
113 | + } | ||
114 | + | ||
115 | + | ||
116 | + /* | ||
117 | + * 批量推送消息 | ||
118 | + * @type vmessageList :list | ||
119 | + * @param vmessageList: | ||
120 | + * | ||
121 | + * @type vtagList :list | ||
122 | + * @param vtagList | ||
123 | + * | ||
124 | + * @return : return message handle list | ||
125 | + */ | ||
126 | + | ||
127 | + | ||
128 | + public function batch_publish_message($vmessageList, $vtagList = null ,$routingKey=null){ | ||
129 | + $params = array( | ||
130 | + 'topicName' => $this->topic_name, | ||
131 | + ); | ||
132 | + | ||
133 | + if($routingKey !=null){ | ||
134 | + $params['routingKey'] = $routingKey; | ||
135 | + } | ||
136 | + $n = 1 ; | ||
137 | + if( is_array($vmessageList) && !empty($vmessageList)) | ||
138 | + { | ||
139 | + foreach ($vmessageList as $msg){ | ||
140 | + $key = 'msgBody.' . $n ; | ||
141 | + if($this->encoding){ | ||
142 | + $params[$key] = base64_encode($msg); | ||
143 | + } | ||
144 | + else | ||
145 | + { | ||
146 | + $params[$key] = $msg; | ||
147 | + } | ||
148 | + $n += 1 ; | ||
149 | + } | ||
150 | + } | ||
151 | + if ($vtagList != null && is_array($vtagList) && !empty($vtagList)) | ||
152 | + { | ||
153 | + $n = 1 ; | ||
154 | + foreach ($vtagList as $tag){ | ||
155 | + $key = 'msgTag.' . $n ; | ||
156 | + $params[$key] = $tag ; | ||
157 | + $n += 1 ; | ||
158 | + } | ||
159 | + } | ||
160 | + | ||
161 | + $msgList = $this->cmq_client->batch_publish_message($params); | ||
162 | + | ||
163 | + $retMessageList = array(); | ||
164 | + foreach ($msgList as $msg){ | ||
165 | + if(isset($msg['msgId'])){ | ||
166 | + $retmsgId = $msg['msgId']; | ||
167 | + $retMessageList [] = $retmsgId; | ||
168 | + } | ||
169 | + } | ||
170 | + return $retMessageList; | ||
171 | + | ||
172 | + } | ||
173 | + /* 列出Topic的Subscriptoin | ||
174 | + | ||
175 | + @type topic_name :string | ||
176 | + @param topic_name: | ||
177 | + | ||
178 | + @type searchWord: string | ||
179 | + @param searchWord: 订阅关键字 | ||
180 | + | ||
181 | + @type limit: int | ||
182 | + @param limit: 最多返回的订阅数目 | ||
183 | + | ||
184 | + @type offset: string | ||
185 | + @param offset: list_subscription的起始位置,上次list_subscription返回的next_offset | ||
186 | + | ||
187 | + @rtype: tuple | ||
188 | + @return: subscriptionURL的列表和下次list subscription的起始位置; 如果所有subscription都list出来,next_offset为"". | ||
189 | + */ | ||
190 | + public function list_subscription($searchWord ="", $limit = -1, $offset =""){ | ||
191 | + $params = array('topicName' => $this->topic_name); | ||
192 | + | ||
193 | + if($searchWord != ""){ | ||
194 | + $params['searchWord'] = $searchWord; | ||
195 | + } | ||
196 | + | ||
197 | + if($limit != -1){ | ||
198 | + $params['limit'] = $limit; | ||
199 | + } | ||
200 | + | ||
201 | + if($offset != ""){ | ||
202 | + $params['offset'] = $offset; | ||
203 | + } | ||
204 | + | ||
205 | + $resp = $this->cmq_client->list_subscription($params); | ||
206 | + | ||
207 | + if ($offset == ""){ | ||
208 | + $next_offset = count($resp['subscriptionList']); | ||
209 | + } | ||
210 | + else{ | ||
211 | + $next_offset = $offset + count($resp['subscriptionList']); | ||
212 | + } | ||
213 | + | ||
214 | + if($next_offset >= $resp['totalCount']){ | ||
215 | + $next_offset = ""; | ||
216 | + } | ||
217 | + | ||
218 | + return array("totalCoult" => $resp['totalCount'], | ||
219 | + "subscriptionList" =>$resp['subscriptionList'], | ||
220 | + "next_offset" => $next_offset); | ||
221 | + } | ||
222 | + | ||
223 | + protected function __resp2meta($topic_meta, $resp){ | ||
224 | + if(isset($resp['maxMsgSize'])){ | ||
225 | + $topic_meta->maxMsgSize = $resp['maxMsgSize']; | ||
226 | + } | ||
227 | + if(isset($resp['msgRetentionSeconds'])){ | ||
228 | + $topic_meta->msgRetentionSeconds = $resp['msgRetentionSeconds']; | ||
229 | + } | ||
230 | + if(isset($resp['createTime'])){ | ||
231 | + $topic_meta->createTime = $resp['createTime']; | ||
232 | + } | ||
233 | + if(isset($resp['lastModifyTime'])){ | ||
234 | + $topic_meta->lastModifyTime = $resp['lastModifyTime']; | ||
235 | + } | ||
236 | + if(isset($resp['filterType'])){ | ||
237 | + $topic_meta->filterType = $resp['filterType']; | ||
238 | + } | ||
239 | + | ||
240 | + | ||
241 | + | ||
242 | + } | ||
243 | +} | ||
244 | + | ||
245 | +class TopicMeta | ||
246 | +{ | ||
247 | + | ||
248 | + // default maxMsgSize 65536 | ||
249 | + // default msgRetentionSeconds 86400, one day | ||
250 | + | ||
251 | + /* 主题属性 | ||
252 | + @note: 可修改 | ||
253 | + :: maxMsgSize 消息最大值 | ||
254 | + | ||
255 | + @note: 不可修改 | ||
256 | + :: msgRetentionSeconds 消息最长保存时间,默认为 一天 | ||
257 | + :: createTime 创建时间 | ||
258 | + :: lastModifyTime 上次修改时间 | ||
259 | + */ | ||
260 | + public $maxMsgSize; | ||
261 | + public $msgRetentionSeconds; | ||
262 | + public $createTime; | ||
263 | + public $lastModifyTime; | ||
264 | + | ||
265 | + public function __construct(){ | ||
266 | + $this->maxMsgSize = 65536 ; | ||
267 | + $this->msgRetentionSeconds= 86400; | ||
268 | + $this->createTime = 0; | ||
269 | + $this->lastModifyTime = 0; | ||
270 | + $this->filterType = 1; | ||
271 | + } | ||
272 | + | ||
273 | + public function __toString(){ | ||
274 | + $info = array( | ||
275 | + "maxMsgSize" => $this->maxMsgSize, | ||
276 | + "msgRetentionSeconds" => $this->msgRetentionSeconds, | ||
277 | + "createTime" => $this->createTime, | ||
278 | + "lastModifyTime" => $this->lastModifyTime, | ||
279 | + "filterType" => $this->filterType | ||
280 | + ); | ||
281 | + return json_encode($info); | ||
282 | + } | ||
283 | +} | ||
284 | + |
app/Common/ThirdPartyLogin.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 10/02/2017 | ||
6 | + * Time: 6:23 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | +use App\Common\Enums\LoginType; | ||
12 | + | ||
13 | +/** | ||
14 | + * Class ThirdPartyLogin | ||
15 | + * @package App\Common | ||
16 | + */ | ||
17 | +class ThirdPartyLogin | ||
18 | +{ | ||
19 | + public static function verify($openId, $accessToken, $type) | ||
20 | + { | ||
21 | + if ($type == LoginType::QQ) | ||
22 | + { | ||
23 | + return self::qq_verify($openId, $accessToken); | ||
24 | + } | ||
25 | + else if($type == LoginType::WECHAT) | ||
26 | + { | ||
27 | + return self::wechat_verify($openId, $accessToken); | ||
28 | + } | ||
29 | + } | ||
30 | + | ||
31 | + | ||
32 | + private static function qq_verify($openId, $accessToken) | ||
33 | + { | ||
34 | + $target = "https://graph.qq.com/oauth2.0/me?access_token=".$accessToken; | ||
35 | + $result = Http::Get($target); | ||
36 | + | ||
37 | + if($result != null) | ||
38 | + { | ||
39 | + if (preg_match('/openid":"'.$openId.'"/', $result)) | ||
40 | + { | ||
41 | + return true; | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | + return false; | ||
46 | + } | ||
47 | + | ||
48 | + private static function wechat_verify($openId, $accessToken) | ||
49 | + { | ||
50 | + $target = "https://api.weixin.qq.com/sns/auth?access_token=".$accessToken."&openid=".$openId; | ||
51 | + $result = Http::Get($target); | ||
52 | + | ||
53 | + if($result != null) | ||
54 | + { | ||
55 | + if (preg_match('/"errcode":0,/', $result)) | ||
56 | + { | ||
57 | + return true; | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + return false; | ||
62 | + } | ||
63 | +} |
app/Common/Util/OrderUtil.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 11/03/2017 | ||
6 | + * Time: 11:12 AM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common\Util; | ||
10 | + | ||
11 | + | ||
12 | +class OrderUtil | ||
13 | +{ | ||
14 | + private static function generateOrderId() | ||
15 | + { | ||
16 | + $time_ms_array = explode(" ", microtime()); | ||
17 | + $ms_part = sprintf("%06d", $time_ms_array[0] * 1000 * 1000); | ||
18 | + $s_part = $time_ms_array[1]; | ||
19 | + | ||
20 | + return date('YmdHis', $s_part) . $ms_part . rand(10000000,99999999); | ||
21 | + } | ||
22 | + | ||
23 | + public static function generateRechargeOrderId() | ||
24 | + { | ||
25 | + return 'ykr'.self::generateOrderId(); | ||
26 | + } | ||
27 | + | ||
28 | + public static function generateCosumeOrderId() | ||
29 | + { | ||
30 | + return 'ykc'.self::generateOrderId(); | ||
31 | + } | ||
32 | +} |
app/Common/Utils.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 12/02/2017 | ||
6 | + * Time: 11:06 AM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | + | ||
12 | +class Utils | ||
13 | +{ | ||
14 | + /** | ||
15 | + * @return string | ||
16 | + */ | ||
17 | + public static function guid() | ||
18 | + { | ||
19 | + $timestamp = time(); | ||
20 | + $ranstr = rand(9999, 9999999999); | ||
21 | + return md5($timestamp . $ranstr) . substr(md5($ranstr), 0, 8); | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * xml转为数组 | ||
26 | + */ | ||
27 | + public static function xmlToArray($xmlStr) | ||
28 | + { | ||
29 | + $msg = array(); | ||
30 | + $postStr = $xmlStr; | ||
31 | + | ||
32 | + $msg = json_decode(json_encode(simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA)), true); | ||
33 | + | ||
34 | + return $msg; | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + /** | ||
39 | + * @param $number | ||
40 | + * @param int $precision | ||
41 | + * @return float|int | ||
42 | + */ | ||
43 | + public static function round_up($number, $precision = 3) | ||
44 | + { | ||
45 | + $fig = (int) str_pad('1', $precision, '0'); | ||
46 | + return (ceil($number * $fig) / $fig); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * @param $number | ||
51 | + * @param int $precision | ||
52 | + * @return float|int | ||
53 | + */ | ||
54 | + public static function round_down($number, $precision = 3) | ||
55 | + { | ||
56 | + $fig = (int) str_pad('1', $precision, '0'); | ||
57 | + return (floor($number * $fig) / $fig); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * @param $data | ||
62 | + * @param $key | ||
63 | + * @return mixed | ||
64 | + */ | ||
65 | + public static function array_remove($data, $key) | ||
66 | + { | ||
67 | + if(!array_key_exists($key, $data)){ | ||
68 | + return $data; | ||
69 | + } | ||
70 | + $keys = array_keys($data); | ||
71 | + $index = array_search($key, $keys); | ||
72 | + if($index !== FALSE){ | ||
73 | + array_splice($data, $index, 1); | ||
74 | + } | ||
75 | + return $data; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * @param $day1 | ||
80 | + * @param $day2 | ||
81 | + * @return float|int | ||
82 | + */ | ||
83 | + public static function diffBetweenTwoDays ($day1, $day2) | ||
84 | + { | ||
85 | + $second1 = strtotime($day1); | ||
86 | + $second2 = strtotime($day2); | ||
87 | + | ||
88 | + if ($second1 < $second2) { | ||
89 | + $tmp = $second2; | ||
90 | + $second2 = $second1; | ||
91 | + $second1 = $tmp; | ||
92 | + } | ||
93 | + return ($second1 - $second2) / 86400; | ||
94 | + } | ||
95 | +} |
app/Common/WechatPay.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 09/03/2017 | ||
6 | + * Time: 8:33 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Common; | ||
10 | + | ||
11 | +/** | ||
12 | + * Class WechatPay | ||
13 | + * @package App\Common | ||
14 | + */ | ||
15 | +use App\Common\Enums\PaySource; | ||
16 | + | ||
17 | +/** | ||
18 | + * Class WechatPay | ||
19 | + * @package App\Common | ||
20 | + */ | ||
21 | +class WechatPay | ||
22 | +{ | ||
23 | + /** | ||
24 | + * order Id | ||
25 | + * @var | ||
26 | + */ | ||
27 | + private $order_id; | ||
28 | + | ||
29 | + /** | ||
30 | + * Order price | ||
31 | + * @var | ||
32 | + */ | ||
33 | + private $price; | ||
34 | + | ||
35 | + /** | ||
36 | + * pay description | ||
37 | + * @var | ||
38 | + */ | ||
39 | + private $body; | ||
40 | + | ||
41 | + /** | ||
42 | + * @var | ||
43 | + */ | ||
44 | + private $pay_type; | ||
45 | + | ||
46 | + /** | ||
47 | + * Callback Url | ||
48 | + * @var | ||
49 | + */ | ||
50 | + private $call_back_url; | ||
51 | + | ||
52 | + /** | ||
53 | + * Used for js and mini program | ||
54 | + * @var | ||
55 | + */ | ||
56 | + private $open_id; | ||
57 | + | ||
58 | + /** | ||
59 | + * @var | ||
60 | + */ | ||
61 | + private $refund_fee; | ||
62 | + | ||
63 | + /** | ||
64 | + * @var | ||
65 | + */ | ||
66 | + private $refund_id; | ||
67 | + | ||
68 | + /** | ||
69 | + * @var | ||
70 | + */ | ||
71 | + private $op_user_id; | ||
72 | + | ||
73 | + /** | ||
74 | + * WechatPay constructor. | ||
75 | + * @param $order_id | ||
76 | + * @param $price | ||
77 | + * @param $body | ||
78 | + * @param $pay_type | ||
79 | + * @param $call_back_url | ||
80 | + */ | ||
81 | + public function __construct($order_id="", $price=0, $body="", $call_back_url="", $pay_type=PaySource::APP) | ||
82 | + { | ||
83 | + $this->order_id = $order_id; | ||
84 | + $this->price = $price; | ||
85 | + $this->body = $body; | ||
86 | + $this->call_back_url = $call_back_url; | ||
87 | + $this->pay_type = $pay_type; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * @param mixed $pay_type | ||
92 | + */ | ||
93 | + public function setPayType($pay_type) | ||
94 | + { | ||
95 | + $this->pay_type = $pay_type; | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * @param mixed $open_id | ||
100 | + */ | ||
101 | + public function setOpenId($open_id) | ||
102 | + { | ||
103 | + $this->open_id = $open_id; | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * @param mixed $refund_fee | ||
108 | + */ | ||
109 | + public function setRefundFee($refund_fee) | ||
110 | + { | ||
111 | + $this->refund_fee = $refund_fee; | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * @param mixed $op_user_id | ||
116 | + */ | ||
117 | + public function setOpUserId($op_user_id) | ||
118 | + { | ||
119 | + $this->op_user_id = $op_user_id; | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * @param mixed $refund_id | ||
124 | + */ | ||
125 | + public function setRefundId($refund_id) | ||
126 | + { | ||
127 | + $this->refund_id = $refund_id; | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * @param $success | ||
132 | + * @param $error_messge | ||
133 | + * @param string $payInfo | ||
134 | + * @return array | ||
135 | + */ | ||
136 | + private function response($success, $error_messge, $payInfo="") | ||
137 | + { | ||
138 | + $result = array('success'=>$success, 'error_message'=>$error_messge, 'payInfo'=>$payInfo); | ||
139 | + | ||
140 | + return $result; | ||
141 | + } | ||
142 | + | ||
143 | + | ||
144 | + /** | ||
145 | + * 请求微信API进行微信统一下单 | ||
146 | + * URL地址:https://api.mch.weixin.qq.com/pay/unifiedorder | ||
147 | + */ | ||
148 | + public function getUnifiedOrderInfo() | ||
149 | + { | ||
150 | + $check_result = $this->checkConfigParam(); | ||
151 | + if (!empty($check_result)) | ||
152 | + { | ||
153 | + return $this->response(false, $check_result); | ||
154 | + } | ||
155 | + | ||
156 | + $param = $this->getUnifiedOrderParam(); | ||
157 | + | ||
158 | + //wechat unified order request | ||
159 | + $resultXmlStr = Http::WechatPostWithSecurity($param, config('constants.wechat.unified_order_url')); | ||
160 | + $result = Utils::xmlToArray($resultXmlStr); | ||
161 | + | ||
162 | + if (!$this->checkRespSign($result)) | ||
163 | + { | ||
164 | + return $this->response(false, "统一下单失败"); | ||
165 | + } | ||
166 | + | ||
167 | + switch ($this->pay_type) | ||
168 | + { | ||
169 | + case PaySource::APP: | ||
170 | + $unifiedOrderInfo = $this->getAppUnifiedOrderInfo($result['prepay_id']); | ||
171 | + break; | ||
172 | + case PaySource::JS: | ||
173 | + case PaySource::MINI_PROGRAM: | ||
174 | + $unifiedOrderInfo = $this->getJSUnifiedOrderInfo($result['prepay_id']); | ||
175 | + break; | ||
176 | + case PaySource::NATIVE: | ||
177 | + $unifiedOrderInfo = ['code_url' => $result['code_url']]; | ||
178 | + break; | ||
179 | + | ||
180 | + default: | ||
181 | + $unifiedOrderInfo = $this->getAppUnifiedOrderInfo($result['prepay_id']); | ||
182 | + break; | ||
183 | + } | ||
184 | + | ||
185 | + | ||
186 | + $unifiedOrderInfo["sign"] = $this->sign($unifiedOrderInfo);//生成签名 | ||
187 | + | ||
188 | + return $this->response(true, "", $unifiedOrderInfo); | ||
189 | + } | ||
190 | + | ||
191 | + /** | ||
192 | + * @return mixed|string | ||
193 | + */ | ||
194 | + private function getAppId() | ||
195 | + { | ||
196 | + switch ($this->pay_type) | ||
197 | + { | ||
198 | + case PaySource::APP: | ||
199 | + case PaySource::NATIVE: | ||
200 | + return config('constants.wechat.app_id'); | ||
201 | + break; | ||
202 | + case PaySource::JS: | ||
203 | + return config('constants.wechat.js_id'); | ||
204 | + break; | ||
205 | + case PaySource::MINI_PROGRAM: | ||
206 | + return config('constants.wechat.mini_program_id'); | ||
207 | + break; | ||
208 | + } | ||
209 | + | ||
210 | + return ""; | ||
211 | + } | ||
212 | + | ||
213 | + /** | ||
214 | + * @return string | ||
215 | + */ | ||
216 | + private function getTradeType() | ||
217 | + { | ||
218 | + switch ($this->pay_type) | ||
219 | + { | ||
220 | + case PaySource::APP: | ||
221 | + return "APP"; | ||
222 | + break; | ||
223 | + case PaySource::JS: | ||
224 | + case PaySource::MINI_PROGRAM: | ||
225 | + return "JSAPI"; | ||
226 | + break; | ||
227 | + case PaySource::NATIVE: | ||
228 | + return "NATIVE"; | ||
229 | + break; | ||
230 | + default: | ||
231 | + return "APP"; | ||
232 | + break; | ||
233 | + } | ||
234 | + } | ||
235 | + | ||
236 | + | ||
237 | + /** | ||
238 | + * 获取同意下单参数 | ||
239 | + * @return string | ||
240 | + */ | ||
241 | + private function getUnifiedOrderParam() | ||
242 | + { | ||
243 | + $price=sprintf("%.2f",$this->price); | ||
244 | + $param = array( | ||
245 | + "appid" => $this->getAppId(), | ||
246 | + "body" => $this->body, | ||
247 | + "mch_id" => config('constants.wechat.mch_id'), | ||
248 | + "nonce_str" => $this->getNonceStr(), | ||
249 | + "notify_url" => $this->call_back_url, | ||
250 | + "out_trade_no" => $this->order_id, | ||
251 | + "total_fee" => $price * 100, | ||
252 | + "trade_type" => $this->getTradeType(), | ||
253 | + ); | ||
254 | + | ||
255 | + if ($this->pay_type == PaySource::JS || $this->pay_type == PaySource::MINI_PROGRAM) | ||
256 | + { | ||
257 | + $param['openid'] = $this->open_id; | ||
258 | + } | ||
259 | + | ||
260 | + $sign = $this->sign($param);//生成签名 | ||
261 | + $param['sign'] = $sign; | ||
262 | + $paramXml = "<xml>"; | ||
263 | + foreach ($param as $k => $v) { | ||
264 | + $paramXml .= "<" . $k . ">" . $v . "</" . $k . ">"; | ||
265 | + | ||
266 | + } | ||
267 | + $paramXml .= "</xml>"; | ||
268 | + | ||
269 | + return $paramXml; | ||
270 | + } | ||
271 | + | ||
272 | + /** | ||
273 | + * @param $prepay_id | ||
274 | + * @return array | ||
275 | + */ | ||
276 | + private function getAppUnifiedOrderInfo($prepay_id) | ||
277 | + { | ||
278 | + $unifiedOrderInfo = [ | ||
279 | + "appid" => $this->getAppId(), | ||
280 | + "noncestr" => $this->getNonceStr(), | ||
281 | + "package" => "Sign=WXPay", | ||
282 | + "partnerid" => config('constants.wechat.mch_id'), | ||
283 | + "prepayid" => $prepay_id, | ||
284 | + "timestamp" => substr(time().'',0,10) | ||
285 | + ]; | ||
286 | + | ||
287 | + return $unifiedOrderInfo; | ||
288 | + } | ||
289 | + | ||
290 | + /** | ||
291 | + * @param $prepay_id | ||
292 | + * @return array | ||
293 | + */ | ||
294 | + private function getJSUnifiedOrderInfo($prepay_id) | ||
295 | + { | ||
296 | + $unifiedOrderInfo = [ | ||
297 | + "appId" => $this->getAppId(), | ||
298 | + "nonceStr" => $this->getNonceStr(), | ||
299 | + "package" => "prepay_id=".$prepay_id, | ||
300 | + "signType" => "MD5", | ||
301 | + "timeStamp" => substr(time().'',0,10) | ||
302 | + ]; | ||
303 | + | ||
304 | + return $unifiedOrderInfo; | ||
305 | + } | ||
306 | + | ||
307 | + | ||
308 | + /** | ||
309 | + * 获取随机字符串 | ||
310 | + * @return string | ||
311 | + */ | ||
312 | + private function getNonceStr() | ||
313 | + { | ||
314 | + $nonceStr = md5(rand(100, 1000) . time()); | ||
315 | + return $nonceStr; | ||
316 | + } | ||
317 | + | ||
318 | + /** | ||
319 | + * 检测配置信息是否完整 | ||
320 | + */ | ||
321 | + public function checkConfigParam() | ||
322 | + { | ||
323 | + | ||
324 | + if ($this->getAppId() == "") { | ||
325 | + return "微信APPID未配置"; | ||
326 | + } elseif (config('constants.wechat.mch_id') == "") { | ||
327 | + return "微信商户号MCHID未配置"; | ||
328 | + } elseif (config('constants.wechat.api_key') == "") { | ||
329 | + return "微信API密钥KEY未配置"; | ||
330 | + } | ||
331 | + | ||
332 | + return ""; | ||
333 | + } | ||
334 | + | ||
335 | + public function refund() | ||
336 | + { | ||
337 | + $check_result = $this->checkConfigParam(); | ||
338 | + if (!empty($check_result)) | ||
339 | + { | ||
340 | + return $this->response(false, $check_result); | ||
341 | + } | ||
342 | + | ||
343 | + $param = $this->getRefundInfo(); | ||
344 | + | ||
345 | + //wechat unified order request | ||
346 | + $resultXmlStr = Http::WechatPostWithSecurity($param, config('constants.wechat.refund_url'), true); | ||
347 | + $result = Utils::xmlToArray($resultXmlStr); | ||
348 | + | ||
349 | + if (!$this->checkRespSign($result)) | ||
350 | + { | ||
351 | + return $this->response(false, "退款失败"); | ||
352 | + } | ||
353 | + | ||
354 | + return $this->response(true, "", $result); | ||
355 | + } | ||
356 | + | ||
357 | + private function getRefundInfo() | ||
358 | + { | ||
359 | + $price=sprintf("%.2f",$this->price); | ||
360 | + $refund_fee = sprintf("%.2f", $this->refund_fee); | ||
361 | + $param = array( | ||
362 | + "appid" => $this->getAppId(), | ||
363 | + "mch_id" => config('constants.wechat.mch_id'), | ||
364 | + "nonce_str" => $this->getNonceStr(), | ||
365 | + "out_trade_no" => $this->order_id, | ||
366 | + "out_refund_no" => $this->refund_id, | ||
367 | + "total_fee" => $price * 100, | ||
368 | + "refund_fee" => $refund_fee * 100, | ||
369 | + "op_user_id" => config('constants.wechat.mch_id'), | ||
370 | + ); | ||
371 | + | ||
372 | + $sign = $this->sign($param);//生成签名 | ||
373 | + $param['sign'] = $sign; | ||
374 | + $paramXml = "<xml>"; | ||
375 | + foreach ($param as $k => $v) { | ||
376 | + $paramXml .= "<" . $k . ">" . $v . "</" . $k . ">"; | ||
377 | + | ||
378 | + } | ||
379 | + $paramXml .= "</xml>"; | ||
380 | + | ||
381 | + return $paramXml; | ||
382 | + } | ||
383 | + | ||
384 | + | ||
385 | + /** | ||
386 | + * sign拼装获取 | ||
387 | + * @param Array $param | ||
388 | + * @return String | ||
389 | + */ | ||
390 | + private function sign($param) | ||
391 | + { | ||
392 | + ksort($param); | ||
393 | + $sign = ""; | ||
394 | + foreach ($param as $k => $v) { | ||
395 | + if ($v != "" && !is_array($v)) | ||
396 | + { | ||
397 | + $sign .= $k . "=" . $v . "&"; | ||
398 | + } | ||
399 | + } | ||
400 | + | ||
401 | + $sign .= "key=" . config('constants.wechat.api_key'); | ||
402 | + $sign = strtoupper(md5($sign)); | ||
403 | + return $sign; | ||
404 | + | ||
405 | + } | ||
406 | + | ||
407 | + /** | ||
408 | + * 检查微信回调签名 | ||
409 | + * @param $param | ||
410 | + * @return bool | ||
411 | + */ | ||
412 | + public function checkRespSign($param) | ||
413 | + { | ||
414 | + if ($param['return_code'] == "SUCCESS") { | ||
415 | + $wxSign = $param['sign']; | ||
416 | + unset($param['sign']); | ||
417 | + | ||
418 | + $sign = $this->sign($param);//生成签名 | ||
419 | + | ||
420 | + if ($this->checkSign($wxSign, $sign)) { | ||
421 | + return true; | ||
422 | + } else { | ||
423 | + return false; | ||
424 | + } | ||
425 | + } else { | ||
426 | + return false; | ||
427 | + } | ||
428 | + } | ||
429 | + | ||
430 | + /** | ||
431 | + * @param $type | ||
432 | + * @param $msg | ||
433 | + * @return string | ||
434 | + */ | ||
435 | + public static function returnInfo($type, $msg) | ||
436 | + { | ||
437 | + if ($type == "SUCCESS") { | ||
438 | + return $returnXml = "<xml><return_code><![CDATA[{$type}]]></return_code></xml>"; | ||
439 | + } else { | ||
440 | + return $returnXml = "<xml><return_code><![CDATA[{$type}]]></return_code><return_msg><![CDATA[{$msg}]]></return_msg></xml>"; | ||
441 | + } | ||
442 | + } | ||
443 | + | ||
444 | + /** | ||
445 | + * 签名验证 | ||
446 | + * @param $sign1 | ||
447 | + * @param $sign2 | ||
448 | + * @return bool | ||
449 | + */ | ||
450 | + private function checkSign($sign1, $sign2) | ||
451 | + { | ||
452 | + return trim($sign1) == trim($sign2); | ||
453 | + } | ||
454 | +} |
app/Console/Commands/DayIncome.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Console\Commands; | ||
4 | + | ||
5 | +use App\Modules\Models\DayIncome\DayIncome; | ||
6 | +use App\Repositories\Business\RentRepository; | ||
7 | +use Illuminate\Console\Command; | ||
8 | + | ||
9 | +class DayProfit extends Command | ||
10 | +{ | ||
11 | + /** | ||
12 | + * The name and signature of the console command. | ||
13 | + * | ||
14 | + * @var string | ||
15 | + */ | ||
16 | + protected $signature = 'DayProfit {--day=}'; | ||
17 | + | ||
18 | + | ||
19 | + /** | ||
20 | + * The console command description. | ||
21 | + * | ||
22 | + * @var string | ||
23 | + */ | ||
24 | + protected $description = '每日的收益数据整理'; | ||
25 | + | ||
26 | + | ||
27 | + protected $rent; | ||
28 | + | ||
29 | + | ||
30 | + public function __construct(RentRepository $rent) | ||
31 | + { | ||
32 | + parent::__construct(); | ||
33 | + $this->rent = $rent; | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Execute the console command. | ||
38 | + * | ||
39 | + * @return mixed | ||
40 | + */ | ||
41 | + public function handle() | ||
42 | + { | ||
43 | + // | ||
44 | + $day = $this->option('day'); | ||
45 | + | ||
46 | + echo 'ma'.$day; | ||
47 | + exit; | ||
48 | + | ||
49 | + } | ||
50 | +} |
app/Console/Kernel.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Console; | ||
4 | + | ||
5 | +use App\Console\Commands\DayProfit; | ||
6 | +use App\Console\Commands\GetElectricity; | ||
7 | +use App\Console\Commands\OrderDetection; | ||
8 | +use Illuminate\Console\Scheduling\Schedule; | ||
9 | +use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||
10 | + | ||
11 | +class Kernel extends ConsoleKernel | ||
12 | +{ | ||
13 | + /** | ||
14 | + * The Artisan commands provided by your application. | ||
15 | + * | ||
16 | + * @var array | ||
17 | + */ | ||
18 | + protected $commands = [ | ||
19 | + // | ||
20 | + Commands\DayProfit::class, | ||
21 | + ]; | ||
22 | + | ||
23 | + /** | ||
24 | + * Define the application's command schedule. | ||
25 | + * | ||
26 | + * @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
27 | + * @return void | ||
28 | + */ | ||
29 | + protected function schedule(Schedule $schedule) | ||
30 | + { | ||
31 | +// $schedule->command(DayProfit::class)->everyMinute()->appendOutputTo('day.log');; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Register the Closure based commands for the application. | ||
36 | + * | ||
37 | + * @return void | ||
38 | + */ | ||
39 | + protected function commands() | ||
40 | + { | ||
41 | + require base_path('routes/console.php'); | ||
42 | + } | ||
43 | +} |
app/Exceptions/Api/ApiException.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: billy | ||
5 | + * Date: 11/02/2017 | ||
6 | + * Time: 1:49 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Exceptions\Api; | ||
10 | + | ||
11 | +use Exception; | ||
12 | + | ||
13 | +/** | ||
14 | + * Class ApiException | ||
15 | + * @package App\Exceptions\Api | ||
16 | + */ | ||
17 | +class ApiException extends Exception | ||
18 | +{ | ||
19 | + /** | ||
20 | + * @var | ||
21 | + */ | ||
22 | + private $response_code; | ||
23 | + | ||
24 | + /** | ||
25 | + * @var | ||
26 | + */ | ||
27 | + private $param; | ||
28 | + | ||
29 | + | ||
30 | + /** | ||
31 | + * ApiException constructor. | ||
32 | + * @param string $code | ||
33 | + * @param int $message | ||
34 | + * @param array $param | ||
35 | + * @param int $response_code | ||
36 | + */ | ||
37 | + public function __construct($code, $message, $param=array(), $response_code=200) | ||
38 | + { | ||
39 | + $this->code = $code; | ||
40 | + $this->message = $message; | ||
41 | + $this->param = $param; | ||
42 | + $this->response_code = $response_code; | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * @return mixed | ||
47 | + */ | ||
48 | + public function getResponseCode() | ||
49 | + { | ||
50 | + return $this->response_code; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * @return mixed | ||
55 | + */ | ||
56 | + public function getParam() | ||
57 | + { | ||
58 | + return $this->param; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * @param mixed $response_code | ||
63 | + */ | ||
64 | + public function setResponseCode($response_code) | ||
65 | + { | ||
66 | + $this->response_code = $response_code; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * @param mixed $param | ||
71 | + */ | ||
72 | + public function setParam($param) | ||
73 | + { | ||
74 | + $this->param = $param; | ||
75 | + } | ||
76 | +} |
Please
register
or
login
to post a comment