管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。/ X/ i8 u* j% r& ~' D
1.添加商品信息
5 {# i0 I3 h6 d2.添加图片
0 d, ^$ q! F6 y! `1 b0 r' ~& z3.查询所有产品' c* U! b" ^( o* v+ D! V* B. B
4.查询某个具体产品信息
0 x* H) h2 |% ~1 j" H: D6 B5 h4 b5.删除某个产品5 n# g; S/ N0 l4 o' [: M9 Z q3 S2 o
6.删除图片7 D& \1 C( S3 N0 x' G& Q. x4 {% f
7.图像识别$ u9 y! f; Q/ g# u
) m$ V6 Q4 M! l
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey7 H% I; T8 u, z/ n" M5 Q# Z
1 O( S. r' W q$ i3 f2 MPHP示例:" Y! ? h) g& Y$ R: u
- <!--?php
+ l+ c" ^9 u, U3 m6 a - // +----------------------------------------------------------------------$ j: O) X" _# H9 ]: K+ a8 [5 O
- // | JuhePHP [ NO ZUO NO DIE ]2 ~* k" k" z! v2 D% b( ?
- // +----------------------------------------------------------------------
) U( N: I4 @4 w, L$ x, a - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.! O1 E0 I5 P; _! Y
- // +----------------------------------------------------------------------$ T; Q8 Y5 H0 ]7 w- s
- // | Author: Juhedata <info@juhe.cn-->/ Y$ g# m" F5 ?$ ~8 I( \2 l
- // +----------------------------------------------------------------------
* D" {5 q% l6 t- o U - % e2 D0 w/ k8 ~" S* Z4 C: |
- //----------------------------------! T6 W3 D$ B: X+ i( W. b8 o% K6 F' k% R
- // 图像识别调用示例代码 - 聚合数据$ g/ s& _+ k$ |5 t: e! Q! s; a( G
- // 在线接口文档:http://www.juhe.cn/docs/117; Q8 c" g/ @5 E {! c# X
- //----------------------------------
) \# [+ W8 H" L2 v+ Z: {; [ - # O( {9 A( M! ~6 `- V7 j. t5 l5 t
- header('Content-type:text/html;charset=utf-8');0 I7 N# K& L J8 ^0 E* P8 j
-
9 W2 T. l: S: d& V - 9 H O; G( e' s( Z2 [! A
- //配置您申请的appkey$ D, I% W4 T+ s7 @
- $appkey = "*********************";2 ^9 e) L+ c, k( J5 H
-
6 w7 s2 T5 @9 L& r -
% W7 s) }$ @1 m+ p3 ? - 9 D5 ]$ f9 p0 w, H5 C
-
( o# v+ D7 }( _6 N - //************1.图像上传************
: ~5 {$ W. f3 o5 V- j$ n9 G - $url = "http://japi.juhe.cn/image_recognition/upload";
$ D; L7 N/ f$ Y4 h8 T& n. ^6 T2 W - $params = array(
/ f% Q7 c9 U; R* g. ^( o - "file" => "",//上传的单张图片
" o' R% q4 H& H% v3 L - "key" => $appkey,//APP Key
0 H" N4 I+ F0 E+ b9 F0 |! n - "pname" => "",//包名
8 H1 L O) \3 o! C% Z; ^ - );8 p1 u0 ]/ A6 D7 t
- $paramstring = http_build_query($params);
! J. D/ M, `0 n3 J# K+ S+ A, T - $content = juhecurl($url,$paramstring,1);
+ d c6 H/ {) d$ m# b/ l# y: ^! p - $result = json_decode($content,true);
; p. s) F9 F$ Q3 h - if($result){5 ?! X7 b" V- w5 j
- if($result['error_code']=='0'){' V3 b' M z9 F7 x0 u
- print_r($result);
( W. a3 B& y2 [0 Y6 _6 a1 J% C/ C - }else{
. U# K0 R% i6 P* r' L( u) h - echo $result['error_code'].":".$result['reason'];
, a0 D, d+ c3 n8 v% @ - }
( ~+ v1 g6 y/ C. ^0 \# z - }else{
' `1 D6 J2 Y& b4 [' B( b- a5 { - echo "请求失败";
8 p: Z, E& b/ C/ b0 x: B) B - }0 P9 I8 o8 x( Y0 {- O; A: X
- //**************************************************
3 q2 L; R3 n! y - ! Z( L8 B+ S2 l
-
( B9 X7 K% W' d% y! z -
( N; i# t! l) j* W: ^, T5 F - ' M- V, [$ d; l* Y: `4 f
- //************2.查寻上传图像信息************
% S- [) o4 M$ E0 E. _; }! c - $url = "http://japi.juhe.cn/image_recognition/findAll";
2 f2 c! u" A+ ?/ ^; T - $params = array(! b! d- K" n3 N/ N% `
- "key" => $appkey,//APP Key
) Y j$ p3 q9 W) n R# K - );; O1 p) k0 m- E) g
- $paramstring = http_build_query($params);$ E% `; o8 q( G, A
- $content = juhecurl($url,$paramstring);
% c9 |+ q; h- o) v' f. a, r - $result = json_decode($content,true);
I7 n$ [, {. J# t- S" e# [ - if($result){
0 F: }9 S# r" g- E - if($result['error_code']=='0'){
% n/ R+ P% P3 R+ L1 F8 m4 H - print_r($result);3 Q; k8 H. w0 t! ^3 H) R( l
- }else{* f1 g, h, B) L" L+ J
- echo $result['error_code'].":".$result['reason'];0 ]5 r/ I6 [: _7 f
- }2 l2 \' e! E! R- D# j& u7 o3 Z
- }else{
* p, `9 ]% n- w- p+ g9 ] - echo "请求失败";$ K- w: O) s N) }% v3 |
- }, @' P+ J) D0 [3 ^2 W
- //**************************************************+ _9 H q z* B" }5 H- \
- ' x2 g$ s: D. Z$ J9 ]
- 4 b/ v) T5 v* M1 @& z9 o& G0 h
-
5 j! Y# k7 ?: e. V - 8 G/ X! y8 l- S& w
- //************3.删除图像信息************' {2 j/ |0 J+ A
- $url = "http://japi.juhe.cn/image_recognition/delete";
0 l/ m! g4 ~; |8 F - $params = array($ ~5 ^% x5 o# P! c" Z' [0 A
- "key" => $appkey,//APP Key
. @; d% n0 a2 p9 t$ }) J; D - "imageId" => "",//图片ID
0 V, p$ R( `* [7 z - );
# W7 x$ F7 G- ]% m. F# P - $paramstring = http_build_query($params);
2 L# z1 j0 N6 K; L6 d - $content = juhecurl($url,$paramstring);6 P( X+ l. E, u5 y0 @
- $result = json_decode($content,true);
# M) \& L2 _: p8 V9 l - if($result){
4 j: P0 s2 {% U3 G) |# ?/ t7 K% p - if($result['error_code']=='0'){
5 I' ?; m7 S0 k5 e: O; b - print_r($result);
( h5 x- t8 f8 s# E% |- y; k8 M$ x - }else{
- r) i& v; w4 w8 @( ^ - echo $result['error_code'].":".$result['reason'];
- E3 S |7 r. ?: v* q - }
" D7 F m0 M' L* T! i - }else{
* t/ G1 _( u) C; g8 W$ I8 O - echo "请求失败";0 Y) @" N0 y- c( z
- }
, @( K, ^9 J, f1 }2 }1 R6 q, Z3 j - //**************************************************+ h4 @5 j1 f5 f
-
, q* ^3 Y0 |+ _4 u5 l* Q -
Q( s$ r9 Y% |" F -
* T6 c' ?% @8 q! U5 j -
7 {$ S+ F6 Y: I; Z/ }. S5 P( h: L - //************4.图像识别************3 H0 ~0 N! g) t' E8 W5 \% l
- $url = "http://japi.juhe.cn/image_recognition/check";
% Q9 \7 T& f! c, g5 S/ O - $params = array(# _# _* v: }% O+ V9 j! Q* A
- "file" => "",//上传的图片
( W( W" n! V# O1 w# [ - "key" => $appkey,//APP Key* d8 v3 B; d7 h" T2 s& j
- "pname" => "",//包名
3 e ^* s h+ n! t$ _7 l, N7 y - "device_name" => "",//设备名称(如android OS或iphone OS)
' ]/ N. a; W' K$ E* h; a - "device_version" => "",//设备版本(如:4.0.3)
% A, L6 ] K* i2 K1 j - "latitude" => "",//纬度
0 V- U* h0 _) k. j6 P* s8 Q2 G* b- h - "longitude" => "",//经度
3 z5 Y: w. h. r" I9 T; d; a7 F - "uuid" => "",//设备id
7 [& O5 }8 g z4 `6 Q - "zone" => "",//请求地区
: J. {4 b9 r# g; t, l( |. f2 ^ - );
- P4 B& R \. Z6 @6 z; { - $paramstring = http_build_query($params);! h' S8 K! K0 I" F5 {7 N1 I
- $content = juhecurl($url,$paramstring,1);
6 k- l |3 U( w) A; | - $result = json_decode($content,true);& L Y, ?2 Z, |7 P) q2 p2 y/ l
- if($result){
5 V: w" ~/ P' \7 d0 O - if($result['error_code']=='0'){
; z' D' |* F: N2 P, f# i' m. g - print_r($result);8 Z. q, A0 H4 u& Z- u- N! r" V; G! y
- }else{
, \7 `. q; o" E; }( a; e, Z - echo $result['error_code'].":".$result['reason'];
3 ^9 L& k+ z5 J8 P7 Z- h( |# `$ ] - }6 o* z( f% _# B3 A
- }else{
2 l, I* t0 j6 h+ Z6 i; F9 m - echo "请求失败";0 y# a0 W2 A9 y+ T- j( u, |
- }2 w t& r$ x% e
- //**************************************************
( Y1 Y+ V4 ]5 ?& S& f+ v - ' m( G# A1 ]# J- O4 E% K0 h8 p- D
-
3 s3 J! R1 N S, C5 n1 Q -
& b `4 r3 H3 z3 X I d3 H: ? - 7 [% V; w. i) e# B; a
-
6 @4 H+ G& f' O3 F. ~$ s( F3 l4 a - /**) a( X( ]8 [9 l( E
- * 请求接口返回内容
. F: B" t- U" {1 H! V( M# [2 f - * @param string $url [请求的URL地址]/ |5 Z$ d" B$ j+ ~
- * @param string $params [请求的参数]. L( {$ y3 s8 |" h
- * @param int $ipost [是否采用POST形式]; `' Q9 m$ {, ^) C2 K5 f4 m& E
- * @return string" z; e8 M- z' [
- */0 A! V+ @# S+ i
- function juhecurl($url,$params=false,$ispost=0){
2 E4 X3 I! O- m5 t - $httpInfo = array();9 h% e# e6 |' B( I7 o" _3 [
- $ch = curl_init();
/ K8 P! U E- D( a; |: J9 F; l -
3 k5 u, X9 I( H+ ^5 T - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
J% H5 M0 ~; R) m8 w - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );( o9 n4 y L9 L! _7 }, P
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );6 |3 P& O& F$ A5 C
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);" O% Q5 w3 F$ {. O# w
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
( s5 V3 j2 ?* X - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);4 j. a) ~, ?# j# f2 W
- if( $ispost )$ J5 F j* r5 |, `
- {
* }0 [$ m3 l9 ` n1 {5 M# A - curl_setopt( $ch , CURLOPT_POST , true );
" u$ ^( q# j n/ t6 B - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
$ n, i& n! L3 G' f - curl_setopt( $ch , CURLOPT_URL , $url );3 \# ]2 N% s$ g' ?
- }) ^) f& X$ C1 f( C5 v, Y A
- else* \% I3 `) `, W3 `$ x# m$ J
- {
( ]$ ?; Y7 z9 X2 u- a( \& t! f - if($params){
2 c9 b) B0 F; S4 _3 U7 d* ? - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
: e) T& l; j! ], q" ^" h, e - }else{5 g8 E F5 q+ ]2 q% C' H1 N
- curl_setopt( $ch , CURLOPT_URL , $url); B& ?8 c$ M' b2 X2 c- w; `( y( F
- }' m8 {+ q- f# \
- }/ Y% ^3 Z- f9 p2 P$ B
- $response = curl_exec( $ch );
! a* z% O. V* x5 }0 ]9 J - if ($response === FALSE) {* R% `7 }5 {% [
- //echo "cURL Error: " . curl_error($ch);7 E" D `' \$ w
- return false;
I t9 Y- T r( Y8 ~3 g3 S - }4 f3 K* y, o/ q; G3 b; U2 `
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
1 X$ U) j( e1 l- g - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );. g) J" p" s5 f
- curl_close( $ch );6 G0 i9 g. i) [
- return $response;- T. I; o! v n0 P) r
- }
复制代码 " }0 y9 \& k- H" t* x. M, P& o
3 U% m- V! r$ W: O7 [& o, y |
|