管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。* y; _$ I0 \4 v
1.添加商品信息" s K' N! d$ K$ j2 K
2.添加图片2 ?* x7 ?1 }8 f9 b
3.查询所有产品
( i4 n. F+ t8 D1 G6 E8 l+ n4.查询某个具体产品信息7 Z& G! c& c/ w# Y$ j# Q) a3 k8 W& K
5.删除某个产品 V! D. q6 i, Y" e+ S$ g8 A
6.删除图片
* V" a* f& m$ o( k& S7.图像识别
. s& q& ]. P: \1 G! n$ P$ C$ \
! G: G& Y7 u( M% X+ o图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
8 `$ E/ o8 O$ c" Q4 v# z5 Y
: L( N( S" f$ f4 V% GPHP示例:/ a7 ?+ D P, \) Q' W+ w0 ~
- <!--?php
" e6 Y0 f) c; b/ f - // +----------------------------------------------------------------------3 ]) Y ?" z% Y% A# }
- // | JuhePHP [ NO ZUO NO DIE ]' D* |4 a- [5 b! |3 t3 I* n
- // +----------------------------------------------------------------------
0 k$ t" H9 \" F- e! a) Q/ G0 S% j - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.5 J2 G$ {. ^5 |- \+ U; K
- // +----------------------------------------------------------------------, r; h0 M2 K3 s5 C% x2 t' d7 o$ M
- // | Author: Juhedata <info@juhe.cn-->4 X/ e- O! K: x# D2 B: K
- // +----------------------------------------------------------------------
c/ K( M _( e8 M5 g% b& j9 l: c2 U" } - % z6 B" u. N+ [. c
- //----------------------------------
0 m4 F0 u6 Q. ^! N3 A0 f- w - // 图像识别调用示例代码 - 聚合数据
1 \2 ?: ^! e# [! |- u% y% O0 a - // 在线接口文档:http://www.juhe.cn/docs/117
* I4 H* `9 N' L - //----------------------------------
' G4 N; u6 ^7 D. P3 o -
; V* ?1 {! {* f Y/ P* N. [1 Q - header('Content-type:text/html;charset=utf-8');
( Q: \4 e, }0 \1 r - 8 c' a3 N" Z" q# g( u
- 9 ]. K/ q- l( \& K3 g* x" f
- //配置您申请的appkey
# b0 L0 j% Y/ o - $appkey = "*********************";2 @' f* ]0 Q3 H8 e
- & s) R* x- l% c( F# @5 K
- ! w9 K4 o2 i; }! W H' y
-
) M1 z$ z9 l+ P+ Q( b7 u3 T -
' R$ D6 S# L2 m g4 d8 l - //************1.图像上传************+ l% _$ @& w0 ~* G' J0 e& P$ [+ i- P
- $url = "http://japi.juhe.cn/image_recognition/upload";* o, e, R6 J: [
- $params = array($ X' l% D+ i u" y
- "file" => "",//上传的单张图片/ E5 r; E( s/ Y, p1 i
- "key" => $appkey,//APP Key. e# Z6 E7 \: g
- "pname" => "",//包名
9 m# a6 T" r6 ?) p* l - );' F% ~+ v! S/ H3 _" g
- $paramstring = http_build_query($params);
9 T* A( r# a% a5 \ ` - $content = juhecurl($url,$paramstring,1);
, D9 R+ e3 r+ z/ e0 s - $result = json_decode($content,true);& d/ J' p5 B5 u/ p1 g7 r- W I
- if($result){: z y6 \$ E% L# C7 p. c9 w: S" M2 Y
- if($result['error_code']=='0'){, z+ q% U# R% N8 ?0 z% d, E, u% r
- print_r($result);
/ a" y3 m/ G: { \4 e - }else{9 b( l, E# L) A: L3 }( F* {
- echo $result['error_code'].":".$result['reason'];! H1 _( V. u% j( |
- }
2 q% E+ J, ?0 ?5 d/ t, O w" u - }else{
7 `1 S% {, y8 n2 S# c7 Q t - echo "请求失败";! U1 z- w f' C; q( F0 e
- }
7 G6 Z9 { j1 a - //**************************************************5 [; B6 ~% k/ P2 X0 Q$ u$ A" r
- 6 }* m: q6 T' `
- + z. {9 B' \# |
-
9 o$ C6 G( x0 e3 Y' r0 c# ^% b - 5 s; |& ^$ c% T+ @
- //************2.查寻上传图像信息************) C0 f* `/ N6 F% m( e9 C: t
- $url = "http://japi.juhe.cn/image_recognition/findAll";! J6 ` Y9 h1 X) ]
- $params = array(
" v' {9 n% p: A9 t0 {7 ^ - "key" => $appkey,//APP Key
3 V( c3 d) `) Y% m - );6 f' X* j$ ^' P9 }8 Q; w) M
- $paramstring = http_build_query($params);
# o( W) V# s: c' f8 A - $content = juhecurl($url,$paramstring);
, a* T, h' ~4 C+ s5 A6 Q7 e - $result = json_decode($content,true);& [, s+ U/ d% q' A. ~1 t
- if($result){& t3 o* j/ p" b! b; X$ q2 V
- if($result['error_code']=='0'){
+ l4 `$ V9 C; ~6 @1 C% q- b- M# X - print_r($result);
" Q9 f0 x* q# ?/ g5 a7 w3 w/ I% n - }else{* M5 f7 N; o O
- echo $result['error_code'].":".$result['reason'];
2 v; y z5 P' S; o8 g4 W5 ` - }
) {" e( F) T, }/ B - }else{
/ C0 {2 t, C5 _ K! I* [ G! H - echo "请求失败";4 A& V s' \! a3 v
- }
/ X) D9 h. X+ e" r9 P" T! M/ ] - //**************************************************
; E# u) X, J9 R, ~! m5 } - 1 W1 Y p; {3 U* s& {6 g! J
-
/ H4 K# \' G; L -
+ v7 \1 R- {) m* y: C) w6 D: M: k - 4 W: V% ^. {# z$ J2 Y9 U) C* V
- //************3.删除图像信息************. n- G. Y ]& |0 Y$ U" S9 t
- $url = "http://japi.juhe.cn/image_recognition/delete";
]2 y2 t2 f( @ - $params = array(1 x+ [3 C, G c4 s* f6 i
- "key" => $appkey,//APP Key0 d9 I/ O2 X9 g! P
- "imageId" => "",//图片ID
: C6 o( w m% R% d - );
: B( f% \" F0 U - $paramstring = http_build_query($params);
K; V- ]; }4 Y' ?* H: Y/ w - $content = juhecurl($url,$paramstring);+ Z$ `: D! u, ?( m
- $result = json_decode($content,true);
) M4 |9 s2 m+ i) P/ J! f - if($result){( _4 Y6 ?7 n- O2 j" O; l
- if($result['error_code']=='0'){
5 E# L. M5 {3 ^9 ? - print_r($result);& | d& |3 g" I- @
- }else{/ k3 z! I8 f$ g* v" k
- echo $result['error_code'].":".$result['reason'];9 p9 Q2 t5 d5 H
- }. ^1 a6 G; ]; ?8 {" P/ |: M; Q
- }else{
7 E' t5 Q2 H* c - echo "请求失败";
& q4 @1 r+ |6 g( E- S - }
( [ D6 E2 s- l! B1 s - //**************************************************
. `& h8 e4 O4 N - 6 u7 l' x) N* v0 }% C8 z
-
; r5 i/ D. ` g2 O. ?+ v -
9 t% f2 o3 C) M8 k8 L* I9 g: ~& s - 3 B, ^/ O, Q/ L0 t) d
- //************4.图像识别************
6 U: o6 a9 r) p9 s% W - $url = "http://japi.juhe.cn/image_recognition/check";$ H) ?( e+ T$ Z# e( F& P# u F
- $params = array(% _8 y" d- M* f3 [
- "file" => "",//上传的图片
+ E j$ u4 Z& x/ e6 {: _: } - "key" => $appkey,//APP Key D G$ X4 o: ], V: H' z6 W! j* b
- "pname" => "",//包名; b7 s9 l9 W8 \1 `
- "device_name" => "",//设备名称(如android OS或iphone OS)7 e; Q6 E# K' |9 }; T$ P
- "device_version" => "",//设备版本(如:4.0.3)
/ T, h y& s2 P9 ~# Q& q+ C - "latitude" => "",//纬度
% B0 ~+ B3 r' R7 i, h$ O - "longitude" => "",//经度
4 e* c2 |( \4 n y - "uuid" => "",//设备id6 s+ _4 R4 d0 z, ^, }! X' K$ A
- "zone" => "",//请求地区
' W3 _7 ?: b. R" `2 u+ Y5 W5 p4 U- M - );
- H! y6 q& h U% T0 A8 X6 j2 w - $paramstring = http_build_query($params);
$ x- I( _ ~1 f% o" M. P- v) M9 P - $content = juhecurl($url,$paramstring,1);
: {0 C; \5 x( R, \ A9 P - $result = json_decode($content,true);
' N0 f2 I; j/ [/ U6 d - if($result){' W' a+ C5 J9 z2 U, q4 V! u
- if($result['error_code']=='0'){
) M! n1 k) q1 M - print_r($result);
, [ Y! Q+ r8 @ m% a - }else{- ]" y0 Q) v/ \; K% t
- echo $result['error_code'].":".$result['reason'];
( M( N8 f/ x& e - }8 e& v- w' C' P8 Q
- }else{
4 F" \8 G, Y' ] - echo "请求失败";' `8 [2 u, ?. D7 `3 f" R& C
- }0 A% B+ f- R+ t" K: e! k9 J
- //**************************************************
8 M& A% a4 ?) N) f l -
2 n% c; H* s4 Q8 Q1 U( d5 U -
1 ]1 ?, q. j1 r3 w -
. d: y: ^! c M, a - $ B& I. P( i; ~ Z4 f' T2 Q7 X5 K. L
-
$ U5 X, ^% @, h) P3 a. G - /**$ B% l# c, J: ?) U
- * 请求接口返回内容
# v3 r P* y+ \ - * @param string $url [请求的URL地址]
; H# D4 ?7 T2 K5 l, i - * @param string $params [请求的参数]
. p" X4 h) Y% O; J5 v1 I2 e1 h! N f - * @param int $ipost [是否采用POST形式]& W& p! V$ F8 v) C8 Q2 r
- * @return string
7 E; [9 o8 P$ |6 S' V9 m - */; T8 ~# a8 D4 Q8 X$ x
- function juhecurl($url,$params=false,$ispost=0){7 c7 ^- i1 f! W1 a5 [- D
- $httpInfo = array();
% X% k( E5 Z6 W5 { - $ch = curl_init();- F- G- q4 Q% x' v7 j3 `
- 6 }5 v# j ~% d" T. B5 D: E4 f
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );7 t! U+ I* z# S
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );& N, T% P2 U/ z k5 y, w
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
& J: I! l5 n8 m* l - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
. Q9 o' T( E# O7 r% C - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
9 v! [6 i2 q" c0 G6 }2 z6 S - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);- [ b! l3 w$ Z: _& H5 f1 u/ ^
- if( $ispost ). I2 e0 h4 V- X; V& i& j) \
- {+ @# T9 A o& V" `# y
- curl_setopt( $ch , CURLOPT_POST , true );
' J2 _) D5 p1 r; I( Y) o" I. A - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );- a" N( A0 v) l
- curl_setopt( $ch , CURLOPT_URL , $url );
, R% P' N6 H) `/ T8 ~! j - }' e9 y( m2 M. r5 [# ]- v! `7 R* T
- else: x) R$ n, I: n
- {. | M! Y" @' m3 B8 S* Y6 H
- if($params){" Z2 J( d3 ]1 Z; S s# Z
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );$ u9 R* I9 O. o- v' ?, k9 c3 l
- }else{* _$ ]/ P3 n% k. D J
- curl_setopt( $ch , CURLOPT_URL , $url);( O5 ` n, Z9 Z
- }
! q7 {3 o( X0 U7 o - }
" g1 U- L* v4 u* L+ ?' r - $response = curl_exec( $ch );, W8 W; D# @6 F1 s2 \" z
- if ($response === FALSE) {& T: i' o: H1 t8 t" o, n
- //echo "cURL Error: " . curl_error($ch);/ ?5 j1 c9 |% c) s- }
- return false;
, I, q ?- h; \0 P - }. g$ T, k# d/ V8 t( h6 k( F+ w* O
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );* Z; }6 S- W7 I4 {9 {
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
* |: {* P- Y% V6 ^7 R0 P - curl_close( $ch );
) n- q& L( Y9 w: Q5 L( m, o% W - return $response;( D5 @$ a6 t- ?/ [* x! g
- }
复制代码 ( m) i( u! h+ u! ]. d% i" x( j& i
+ N3 n6 \. z! ?+ r
|
|