管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
" u$ b: N% ~4 B/ O1.添加商品信息
9 [8 T1 O# T5 ?/ E. m7 S2.添加图片. ~& y# [: t# _6 l5 K5 L* j! q8 n8 D
3.查询所有产品
5 H4 N1 `4 m: ]' p1 p. {; ~( U+ Y4.查询某个具体产品信息$ g5 l f, K7 |( u
5.删除某个产品; q! M! x& ?$ K4 e3 k, M
6.删除图片
+ c/ {! U- R5 b0 j. v4 Z7.图像识别
% m' \" _+ b9 E) n1 A' l
+ e0 \& Z4 @ D W7 t图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
! Z1 e6 V1 q1 c% y' J) S) _6 P- Y9 l
PHP示例:6 V, K: M$ L2 ^* @* W6 R( i* x! k
- <!--?php1 D5 D% W( {' t6 [; P+ j
- // +----------------------------------------------------------------------
9 ~5 }0 X& }7 ~, Y. k# v) q9 g6 E* I - // | JuhePHP [ NO ZUO NO DIE ]9 `! j- f4 ]6 r: q
- // +----------------------------------------------------------------------
+ |* P; B: Z8 Y. Q; j2 F/ N5 ^( c - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.6 x, q( U# y/ n! e9 y
- // +----------------------------------------------------------------------, z" n3 J: ?) S" ]
- // | Author: Juhedata <info@juhe.cn-->% F3 ]. B& V X" A% k. x) m
- // +----------------------------------------------------------------------
5 V( L) k" q+ G# G - / W: q" k+ x( ^1 U
- //----------------------------------! ~) }! |6 h/ y# R
- // 图像识别调用示例代码 - 聚合数据
2 U5 B# C7 Q2 C+ G/ C - // 在线接口文档:http://www.juhe.cn/docs/117: v9 L% t- O; {/ b, N
- //----------------------------------% z7 \' G7 g N
-
& P3 M$ e: [6 q6 o1 L8 f" D6 o - header('Content-type:text/html;charset=utf-8');
1 i( L. O- d6 k2 w( X5 O- m1 D3 P, F, _1 R - 5 n/ k% X# i0 K; H
- $ ]3 }$ g+ r0 Y# l7 e3 Q
- //配置您申请的appkey
; m8 O; j$ {/ N' j" s - $appkey = "*********************";3 z' U% t$ N- R _; t2 b9 V6 t% K
-
) d/ C' x, A1 g6 u7 \ -
3 U Q- x8 k, w9 S) P* L' u0 { - / l2 }+ Z" {* ?) R/ Q
- $ `. W" Z6 r# Z
- //************1.图像上传************
7 A& \4 [! N7 I) y8 \- m - $url = "http://japi.juhe.cn/image_recognition/upload";
9 }( F# c! _6 l - $params = array(
- X" p9 ~8 i$ C4 \6 U) w - "file" => "",//上传的单张图片: \, c7 Y% l+ f+ v. s- T
- "key" => $appkey,//APP Key' _6 Y% b4 j9 g" s1 _; l
- "pname" => "",//包名
9 z+ E8 a5 X$ O7 F( E - );
6 [0 _% I. u) F" N - $paramstring = http_build_query($params);
9 A6 X) P+ i6 W# Q' }5 x( r+ x - $content = juhecurl($url,$paramstring,1);% w0 E5 K/ m `- {1 P5 M2 Q
- $result = json_decode($content,true);, f2 n9 j3 ?; T8 D, H! W" E4 Y
- if($result){
, L$ X1 m6 Z2 J& m) N6 T9 Z5 n7 R - if($result['error_code']=='0'){
0 S( u9 }3 N# p7 M/ k! W$ {, t( w& E - print_r($result);, n; Z ?2 j) X1 L0 f
- }else{
: W/ k6 L$ @9 K7 v9 h7 h6 R - echo $result['error_code'].":".$result['reason'];! ^1 a( j; m9 `( t
- }# s1 t: J2 Z8 b. G( [7 X
- }else{
9 y S) K: l/ c - echo "请求失败"; ^: E9 H3 w( x4 c$ f
- }
* q) Z/ e6 J" E2 D7 y7 S - //**************************************************
" y" p5 m4 Y+ ]9 H. g' b% b - * G! M( B5 z) {- w/ x) a2 }6 l* M( k
- : o4 [# ]" ~7 e
-
. ~" P; ~! S8 C" V -
7 S& j: o, ]3 V; S - //************2.查寻上传图像信息************3 i: J* i4 d3 h$ B
- $url = "http://japi.juhe.cn/image_recognition/findAll";8 P; h8 W# G4 D' s, ^, F
- $params = array(3 F$ L9 c- a7 m- r# X
- "key" => $appkey,//APP Key7 C) o9 T. Z5 z+ P$ n! m: B
- );
: \9 ~( z" `) l9 [1 K - $paramstring = http_build_query($params);
4 d& C+ L( V! `6 s7 [ - $content = juhecurl($url,$paramstring);0 b7 F- s5 o0 T; {" g
- $result = json_decode($content,true);
h8 o5 U* r0 G/ i3 l7 R% H4 A - if($result){
4 m/ v1 o0 g4 v' R* |5 e0 W; c - if($result['error_code']=='0'){5 o9 _+ R8 E+ D1 b
- print_r($result);' j; T: b7 X% h6 y( ?
- }else{: G( P* L, c3 r% A
- echo $result['error_code'].":".$result['reason'];
F; k' U/ n0 ~; Y( |0 l) d - }
$ D, `& Q' ]8 ^" i4 |- R& f - }else{; H& i7 a/ U+ z
- echo "请求失败";
- h+ m5 B& p3 M" _( Y- O - }6 g. d( t- k1 a. u! X
- //**************************************************/ C/ w2 C, @7 L% o2 C
-
7 V4 d' ]+ O2 W" L1 ?, j! t - * T7 _! f- z$ b! P" w; o; |
- - \* P: A4 h0 Q% S
-
m5 s1 U* I$ a6 q) \ - //************3.删除图像信息************5 I( @' ?/ i2 V4 M
- $url = "http://japi.juhe.cn/image_recognition/delete";# v( p* X2 w- n) D# @/ b7 e# U
- $params = array(- e2 p9 y. r( y# C2 U
- "key" => $appkey,//APP Key
$ R# F4 y4 ~; c5 P6 ^+ ~+ G( j+ x - "imageId" => "",//图片ID
8 }; H: c9 x) r - );
/ x+ t3 G: n0 v( i* s - $paramstring = http_build_query($params);" j$ {7 G2 V6 | g. N( i
- $content = juhecurl($url,$paramstring);
9 t; s$ i$ b% [ G3 P; o3 }5 D - $result = json_decode($content,true);
! y0 J& N8 U7 R, R' I- r - if($result){
- h6 U( x* Q/ s - if($result['error_code']=='0'){0 u1 y4 Y* w5 L- F8 ?9 ?6 k9 z
- print_r($result);. g! P3 M9 a, Q
- }else{
( d5 H! z8 Y5 \' s& m+ i - echo $result['error_code'].":".$result['reason'];
* T: I1 Y j# |3 i - }0 w% c5 p- y* w; w, V2 I/ G3 T
- }else{$ r, J& r$ y, X& e+ p; ~
- echo "请求失败";
) |4 y8 S" i \6 g* A9 W - }
& U" I6 t4 g6 \8 ~" k - //**************************************************
: k' b* x7 k; |) s( Y! [/ ]5 [* h, o -
0 v, \! v2 x0 W' {6 H0 l -
9 _! E- {/ U) d( Z- s8 ] -
. Y" N6 g, \+ I& f4 i& P$ T -
5 x3 U' n2 X% ]4 P! p! k! I - //************4.图像识别************
8 i+ h9 c0 m$ P - $url = "http://japi.juhe.cn/image_recognition/check";
7 h T R3 m/ k: n1 Z6 |+ A$ C - $params = array(/ N8 o# G6 c: f! |3 [
- "file" => "",//上传的图片6 c1 e! Y0 c! B. g, q2 e8 Z
- "key" => $appkey,//APP Key% r, |( }; k5 C9 V2 m- Z1 c8 O
- "pname" => "",//包名
- g* v- p# q1 H0 S0 z! ^9 t - "device_name" => "",//设备名称(如android OS或iphone OS)
; w& P3 O9 l4 a$ u' d6 b n$ x) O - "device_version" => "",//设备版本(如:4.0.3)
; N# y$ c) ] x! k4 e; m5 M - "latitude" => "",//纬度8 [! n8 C& C) H b9 g6 N
- "longitude" => "",//经度
, o- Y+ X9 J% b% Q - "uuid" => "",//设备id9 ?; u3 h! X8 Z7 p. T6 p
- "zone" => "",//请求地区2 X- D5 }6 G! A7 _8 Q& `
- );
0 p; K8 C( e+ A - $paramstring = http_build_query($params);
0 p; f' E. A: E - $content = juhecurl($url,$paramstring,1);
' {& s8 {1 L, K% V - $result = json_decode($content,true);
5 B# T1 T% G! S% H+ z& R; n - if($result){0 Z: n- Q+ j) D2 V- X6 C
- if($result['error_code']=='0'){2 R/ _- o9 o7 b8 c+ f* B
- print_r($result);
9 Q& p9 Y! P7 w' d/ O3 C - }else{
: O# b9 k3 b6 A( E: V1 r+ `3 G - echo $result['error_code'].":".$result['reason'];3 a+ L" ]" h" o& }7 v
- }: B7 y) l2 b' b' B% J' x
- }else{) z6 c9 R- a5 z2 k0 G1 U* S5 j# B' Z
- echo "请求失败";
3 X; |9 X- A& C0 A - }
( `) n+ B/ P: W, |0 r - //**************************************************& S0 A- o1 `3 R3 P! p
-
) i* ?+ {( X5 R3 ` E5 F1 } - & G; \6 u! o1 _2 v$ C; m$ O( H# ?
- ; \3 U( b" ~* B" Z1 U# [( c0 g) N
- 4 Q8 ]% q# r+ s2 _
- & B; J1 @* b. x) R
- /**# Q" i5 u' i/ k3 W/ ^0 D+ |
- * 请求接口返回内容. @- X. p( j" ]+ q$ O2 k
- * @param string $url [请求的URL地址]: x. v' ^) T4 f7 y) C: V
- * @param string $params [请求的参数]) L* k0 V0 o) Z( j) ~* o S/ n7 }
- * @param int $ipost [是否采用POST形式]
$ m5 T3 ]4 Z; y2 a! F - * @return string
5 Z1 n0 A) M7 H3 q' [ - */
7 r7 k. u5 F# A) C* O - function juhecurl($url,$params=false,$ispost=0){8 W* `$ Z7 R: n! R2 s2 i) w
- $httpInfo = array();& E. g, C* k. h7 \
- $ch = curl_init();
: ]- S9 A1 I% v- W, V* X* P4 Z -
; F p8 O" _6 |/ ]+ |8 U' O. D - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); i t) z% j/ _5 }' Z
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
8 ?2 l' ?0 R3 K' E- h( A - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
1 e: F* H5 R9 T% d3 [) b! j/ k: \ - curl_setopt( $ch, CURLOPT_TIMEOUT , 60); \! a) F' f/ E/ G: x
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
" F) L8 N q) [ - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
[5 x2 ]" M! f7 ^& }! }) T - if( $ispost )# d4 Q. i( {- b8 D5 K
- {
2 ^* {" r6 t: K$ P0 w, t+ p - curl_setopt( $ch , CURLOPT_POST , true );
6 O3 L. }: @& W3 | - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );$ W" X; f& l& }5 x1 `. v: ]1 p
- curl_setopt( $ch , CURLOPT_URL , $url );
% H6 r) D0 r3 ^5 o0 L - }6 o9 g F# g, Q+ i
- else
1 h: |7 l% @/ {1 H" c - {
z0 s! k+ P% `3 y7 \, W, C - if($params){& @. Y }, g2 O; v* [
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
, d0 W8 p- ~3 f+ e W0 u - }else{
+ D7 a8 b0 b/ k7 } _ - curl_setopt( $ch , CURLOPT_URL , $url);5 ]: `6 P& o! A+ [' Q7 v. D
- }3 }2 c0 a8 m/ k$ g% ~) q+ K
- }5 W% t5 l; d1 ]7 B6 c' Z
- $response = curl_exec( $ch );* Z% a/ \* A+ b+ ?# n
- if ($response === FALSE) {
1 @' Q4 K' Z8 M3 X - //echo "cURL Error: " . curl_error($ch);
: g7 i% y. U8 f - return false;
' q. g s2 x8 o0 [ - }+ \ x7 R, F, A4 \+ f z
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );+ v2 G* J U% {8 h1 r
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
' }) `$ F5 a( \+ I% \4 m( p8 w - curl_close( $ch );, G+ X- r, X* Y2 T( p( N
- return $response;
) k0 a& w! ]0 {+ h+ H - }
复制代码
9 f! _# t1 D% e- K% n6 e3 ~( }- W# c, J/ w( N; M# S
|
|